I'd like to run a python script, which uses a virtualenv as a service. I've already researched a bit, but couldn't find a working solution. I've put the path of the virtual env python on the first line of the python. The service looks like this:
[Unit]
Description=Telegram Bot Service
After=multi-user.target
[email protected]
[Service]
Type=simple
ExecStart=/usr/bin/python3.7 /home/pi/github/python/telegrambot.py
StandardInput=tty-force
[Install]
WantedBy=multi-user.target
The error:
● telegrambot.service - Telegram Bot Service
Loaded: loaded (/lib/systemd/system/telegrambot.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-03-03 15:04:11 GMT; 3s ago
Process: 15090 ExecStart=/usr/bin/python3.7 /home/pi/github/python/telegrambot.py (code=ex
Main PID: 15090 (code=exited, status=1/FAILURE)
Mar 03 15:04:11 raspberrypi systemd[1]: Started Telegram Bot Service.
Mar 03 15:04:11 raspberrypi systemd[1]: telegrambot.service: Main process exited, code=exite
Mar 03 15:04:11 raspberrypi systemd[1]: telegrambot.service: Failed with result 'exit-code'.
Thanks for any help in advance!
venvpython in the script's shebang but you are invoking it with-in the system python. You need to mark your script as executable and run it directly. You may also want to useWORKINGDIRECTORY=directive to switch to a specific directory before running and theUSER=directive to run as a specific user.