Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1251

Python • rc.local to run a Python Module in virtual enviroment

$
0
0
I have the following structure on my pi:
/home/pi/pirate-mp3:
----.venv
----mp3:
-------- resources
-------- __init__.py
-------- __main__.py

.venv contains my virtual environment for running the module. From SSH terminal if I do the following:

Code:

cd /home/pi/piratie-mp3source /home/pi/pirate-mp3/.venv/bin/activatepython3 -m mp3
Then the module works exactly as I want it to. So far so good. Now I want this to run on start up.

My attempt so far was to edit the rc.local file to include this (before exit 0):

Code:

exec 2> /tmp/rc.local.log      # send stderr from rc.local to a log fileexec 1>&2                      # send stdout to the same log fileset -x                         # tell sh to display commands before execution. /home/pi/pirate-mp3/.venv/bin/activatesudo -H -u pi PYTHONPATH=/home/pi/pirate-mp3 /home/pi/pirate-mp3/.venv/bin/python/python3 -m mp3
The module runs without sudo normally. But this is what I get from the /tmp/rc.local.log file:

Code:

+ VIRTUAL_ENV=/home/pi/pirate-mp3/.venv+ export VIRTUAL_ENV+ _OLD_VIRTUAL_PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin+ PATH=/home/pi/pirate-mp3/.venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin+ export PATH+ [ -n  ]+ [ -z  ]+ _OLD_VIRTUAL_PS1=#+ PS1=(.venv) #+ export PS1+ VIRTUAL_ENV_PROMPT=(.venv)+ export VIRTUAL_ENV_PROMPT+ [ -n  -o -n  ]+ sudo -H -u pi PYTHONPATH=/home/pi/pirate-mp3 /home/pi/pirate-mp3/.venv/bin/python3 -m mp32024-09-23 14:50:51 xCreatePipe: Can't set permissions (436) for //.lgd-nfy0, Operation not permittedTraceback (most recent call last):  File "<frozen runpy>", line 189, in _run_module_as_main  File "<frozen runpy>", line 148, in _get_module_details  File "<frozen runpy>", line 112, in _get_module_details  File "/home/pi/pirate-mp3/mp3/__init__.py", line 7, in <module>    import RPi.GPIO as GPIO  File "/home/pi/pirate-mp3/.venv/lib/python3.11/site-packages/RPi/GPIO/__init__.py", line 14, in <module>    import lgpio  File "/home/pi/pirate-mp3/.venv/lib/python3.11/site-packages/lgpio.py", line 562, in <module>    _notify_thread = _callback_thread()                     ^^^^^^^^^^^^^^^^^^  File "/home/pi/pirate-mp3/.venv/lib/python3.11/site-packages/lgpio.py", line 504, in __init__    self._file = open('.lgd-nfy{}'.format(self._notify), 'rb')                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^FileNotFoundError: [Errno 2] No such file or directory: '.lgd-nfy-3'

It looks like I do not have a permission set right somewhere - but I honestly don;'t know enough to troubleshoot this :(

Statistics: Posted by RatchetHamser — Mon Sep 23, 2024 7:03 pm



Viewing all articles
Browse latest Browse all 1251

Trending Articles