Quantcast
Viewing all articles
Browse latest Browse all 1234

Python • Re: Bookworm-start script in virtual environment after reboot

On older release of OS I simply run command

Code:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
add aditional line

Code:

@lxterminal -e python3 /home/vlado/Project/main.py
And that's it, main.py was started after reboot

With Bookworm OS I have to do three steps
Line 1: moove to folder Project
Line 2: activation of the virtual environment
Line 3: start of the script main.py

Code:

vlado@raspberry:~ $ cd Projectvlado@raspberry:~/Project $ source env/bin/activate(env) vlado@raspberry:~/Project $ python main.py
When done it manual, it works normally. The question is how to do it to start script automaticaly after reboot?
I did try like below, but no luck.
Any help would be appreciated.

Code:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
Line 4: activation of the virtual environment
Line 5: start of the script main.py

Code:

@lxpanel --profile LXDE-pi@pcmanfm --desktop --profile LXDE-pi@xscreensaver -no-splash@lxterminal -e python3 /home/vlado/Project/source env/bin/activate@lxterminal -e python3 /(env)home/vlado/Project/python main.py

No need to activate the venv, just use the full path for the venv's Python interpreter

Code:

@lxterminal -e /home/vlado/Project/env/bin/python3 /home/vlado/Project/main.py
Python has smarts builtin so that when you do that, it knows it's starting from a venv and will run as if the venv had been previously activated before running your script.

Also the (env) is not part of the path,mit is just shown in the prompt. So that would never work.

Statistics: Posted by memjr — Tue Jan 30, 2024 5:40 am



Viewing all articles
Browse latest Browse all 1234

Trending Articles