Post #2005158
2026-04-17 22:16 UTC
@bryanredeagle
I use pyenv for installing specific python versions for for different projects, and venv for creating virtual environments, if a project need to run in the background, i have two methods, depending the case
For example, after installing pyenv:
pyenv install 3.13.7
pyenv shell 3.13.7
python -m venv /home/auser/project
source /home/auser/project/bin/activate
cd /home/auser/project
pip install apackage
python aproject.py
For running in the background, after installing screen:
screen -dmS projectname /bin/bash -c "source /home/auser/project/bin/activate && cd /home/auser/project && python aproject.py --paramsifrequired"
And for viewing such screen:
screen -r projectname
CTRL+C for stopping the screen
CTRL+A next CTRL+D for screen detach and returning to the console
In a systemd service with a virtual env:
sudo nano /etc/systemd/system/aservice.service
paste:
[Unit]
Description=A service for a server
[Service]
Type=simple
#User=auser
ExecStart=/home/auser/project/bin/python aproject.py
WorkingDirectory=/home/auser/project
TimeoutSec=60
StandardOutput=journal
StandardError=journal
SyslogIdentifier=aproject
Restart=always
[Install]
WantedBy=multi-user.target
CTRL+S for saving and CTRL+X for closing nano
sudo systemctl daemon-reload && sudo systemctl enable aservice && sudo systemctl start aservice && journalctl -feu aservice
Hope this helps you
Replies (0)
No replies.