I have written a script called coinview.py
and it can run on linux. When I trying to run it as systemd
, it raises error
error:ImportError: No module named 'schedule'.
I use pip3
show schedule, it already exist. So i have no idea what's wrong with my script.
I print sys.executable and sys.path in systemd.
[Unit]
Description=coinview deamon
After=rc-local.service
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/home/ubuntu/source/quotation_api
ExecStart=/usr/bin/python3 coinview.py
Restart=always
[Install]
WantedBy=multi-user.target
ubuntu@ip-100-00-40-02:/etc/systemd/system$ pip3 show schedule
Name: schedule
Version: 0.6.0
Summary: Job scheduling for humans.
Home-page: https://github.com/dbader/schedule
Author: Daniel Bader
Author-email: [email protected]
License: MIT
Location: /home/ubuntu/.local/lib/python3.5/site-packages
Requires:
Required-by:
Mar 27 08:40:10 ip-100-00-40-02 python3[8634]: Traceback (most recent call last):
Mar 27 08:40:10 ip-100-00-40-02 python3[8634]: File "coinview.py", line 3, in <module>
Mar 27 08:40:10 ip-100-00-40-02 python3[8634]: import requests,threading,time,schedule,json
Mar 27 08:40:10 ip-100-00-40-02 python3[8634]: ImportError: No module named 'schedule'
Mar 27 08:40:10 ip-100-00-40-02 systemd[1]: coinview.service: Main process exited, code=exited, status=1/FAILURE
Mar 27 08:40:10 ip-100-00-40-02 systemd[1]: coinview.service: Unit entered failed state.
Mar 27 08:40:10 ip-100-00-40-02 systemd[1]: coinview.service: Failed with result 'exit-code'.
Mar 27 08:40:10 ip-100-00-40-02 systemd[1]: coinview.service: Service hold-off time over, scheduling restart.
Mar 27 08:40:10 ip-100-00-40-02 systemd[1]: Stopped coinview deamon.
Apr 09 07:59:03 ip-100-00-40-02 python[12095]: /usr/bin/python3
Apr 09 07:59:03 ip-100-00-40-02 python[12095]: ['/home/ubuntu/source/quotation_api', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x8
pip install schedule
on the command line?sys.path
has? Try raising a dummy exception with it's value just to show it in the service startup log.systemd
probably uses the system-sidepython
to run the script. You can test this by running something likeimport sys; print(sys.executable)
at the top of the script, and saving the output produced bysystemd
#!/usr/bin/python3
at the top of the file to suggest to any process that just tries to run the file as an executable that it should use python3 to run it. That shebang should point to the python interpreter that has theschedule
module installed to its side-packages, which is probably thepython3
at/usr/bin
, but who knows.