Systemd service not recognizing python library

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Systemd service not recognizing python library



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[1]: Started Testing.
Aug 12 02:08:47 raspberrypi python3[1039]: Traceback (most recent call last):
Aug 12 02:08:47 raspberrypi python3[1039]: File "/home/pi/discord/bug.py", line 1, in <module>
Aug 12 02:08:47 raspberrypi python3[1039]: import discord
Aug 12 02:08:47 raspberrypi python3[1039]: ImportError: No module named 'discord'
Aug 12 02:08:47 raspberrypi systemd[1]: bugstart.service: Main process exited, code=exited, status=1/FAILURE
Aug 12 02:08:47 raspberrypi systemd[1]: bugstart.service: Unit entered failed state.
Aug 12 02:08:47 raspberrypi systemd[1]: 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.





User=id is there a user called id?
– Oleksandr Kravchuk
Aug 12 at 2:14


User=id





@OleksandrKravchuk Sorry, that was a mistake, I've removed it from my code. I was typing User=pi and had a brain fart.
– The Tesseract's Shadow
Aug 12 at 2:15






try sudo -H pip install discord or whatever the package name is
– Oleksandr Kravchuk
Aug 12 at 2:17


sudo -H pip install discord





@OleksandrKravchuk Running it right now, I'll let you know if it works.
– The Tesseract's Shadow
Aug 12 at 2:22





@OleksandrKravchuk It worked! Although now I have issues in my code I need to fix. If you put your response as an answer, and explain what it does I'll accept it. Thanks!
– The Tesseract's Shadow
Aug 12 at 3:21









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS