I'm trying to run a python discord bot when my Raspberry Pi starts up. To do this, I've used a systemd service:
[Unit] Description=Testing [Service] Type=idle WorkingDirectory=/home/pi ExecStart=/usr/bin/python3 /home/pi/discord/bug.py [Install] WantedBy=multi-user.target
I have done several test using simpler python programs before, and it all works fine. When trying to run the discord bot, it throws an error at the import statement. For testing I run:
sudo systemctl start bugstart sudo systemctl status bugstart
The output of the status is the following:
bugstart.service - Testing Loaded: loaded (/lib/systemd/system/bugstart.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2018-08-12 02:08:47 UTC; 1s ago Process: 1039 ExecStart=/usr/bin/python3 /home/pi/discord/bug.py (code=exited, status=1/FAILURE) Main PID: 1039 (code=exited, status=1/FAILURE) Aug 12 02:08:46 raspberrypi systemd: Started Testing. Aug 12 02:08:47 raspberrypi python3: Traceback (most recent call last): Aug 12 02:08:47 raspberrypi python3: File "/home/pi/discord/bug.py", line 1, in <module> Aug 12 02:08:47 raspberrypi python3: import discord Aug 12 02:08:47 raspberrypi python3: ImportError: No module named 'discord' Aug 12 02:08:47 raspberrypi systemd: bugstart.service: Main process exited, code=exited, status=1/FAILURE Aug 12 02:08:47 raspberrypi systemd: bugstart.service: Unit entered failed state. Aug 12 02:08:47 raspberrypi systemd: bugstart.service: Failed with result 'exit-code'.
I found out that the commands are run as root, so I figured it might be that the library hand't been installed on root, but I tried importing discord in the command line shell and it worked fine.