2

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!

Silvan
  • 21
  • 1
  • 3
  • Does this answer your question? [How to run a command inside a virtualenv using systemd](https://unix.stackexchange.com/questions/409609/how-to-run-a-command-inside-a-virtualenv-using-systemd) – GAD3R Mar 03 '20 at 15:18
  • 1
    I've used that as a help, but it didn't work with the solution suggested there. – Silvan Mar 03 '20 at 15:20
  • So. You say you put the `venv` python 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 use `WORKINGDIRECTORY=` directive to switch to a specific directory before running and the `USER=` directive to run as a specific user. – cstrutton Oct 24 '20 at 15:45

0 Answers0