系统服务无法识别python库

时间:2018-08-12 02:11:51

标签: python linux systemd

当我的Raspberry Pi启动时,我正在尝试运行python discord机器人。为此,我使用了systemd服务:

[Unit]
Description=Testing

[Service]
Type=idle
WorkingDirectory=/home/pi
ExecStart=/usr/bin/python3 /home/pi/discord/bug.py

[Install]
WantedBy=multi-user.target

我之前已经使用较简单的python程序进行了几次测试,并且一切正常。尝试运行discord bot时,它会在import语句上引发错误。为了测试,我运行:

sudo systemctl start bugstart
sudo systemctl status bugstart

状态输出如下:

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'.

我发现命令是以root身份运行的,所以我发现可能不是在root上安装了库文件,但是我尝试在命令行shell中导入discord并正常工作。

0 个答案:

没有答案