我正在尝试在 ubuntu 18.04 中将 python 程序作为后台服务运行。它导入我已经使用 pip3 安装并在终端上使用 python 命令测试的 zerorpc 模块。但它显示状态:当我尝试将程序作为 dummy.service 运行时失败。以下是我的服务文件:
[Unit]
Description=Dummy Service
[Service]
Type=Simple
ExecStart=/usr/bin/python3 /usr/bin/server.py
[Install]
WantedBy=multi-user.target
下面是启用后的服务状态:
dummy.service - Dummy Service
Loaded: loaded (/lib/systemd/system/dummy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2019-11-26 16:18:57 IST; 5s ago
Process: 4101 ExecStart=/usr/bin/python2 /usr/bin/server.py (code=exited, status=1/FAILURE)
Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: Started Dummy Service.
Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: Traceback (most recent call last):
Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: File "/usr/bin/server.py", line 1, in <module>
Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: import zerorpc
Nov 26 16:18:57 vipul-HP-Notebook python2[4101]: ImportError: No module named zerorpc
Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: dummy.service: Main process exited, code=exited, status=1/FAILURE
Nov 26 16:18:57 vipul-HP-Notebook systemd[1]: dummy.service: Failed with result 'exit-code'.
我不知道为什么会这样。请帮忙!!