Systemd服务无法识别python库

2024-06-16 11:05:56 发布

您现在位置:Python中文网/ 问答频道 /正文

当我的树莓派启动时,我正试图运行一个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语句中抛出一个错误。对于测试,我运行:

^{pr2}$

状态输出如下:

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,它工作得很好。在


Tags: pyhomestatusservicepicodetestingbug