Running python script through crontab can't find imports

此生再无相见时 提交于 2020-01-16 12:35:32

问题


I'm trying to run a python script through crontab, but it can't import any of the libraries that it needs when it is run this way. When I run the scripts outside of crontab, there is no issue, and I know that I have these libraries installed.

Do I need to specify a path to them or something?

Many thanks

crontab file:

SHELL=/bin/bash
MAILTO=jess.chambers@gmail.com
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G1 -S0 >>/tmp/stdout.log 2>&1
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G2 -S20 >>/tmp/stdout.log 2>&1
*/1 * * * * cd ~/Downloads/guichets && python newRdvChecker.py -G3 -S40  >>/tmp/stdout.log 2>&1

Error log:

Traceback (most recent call last):
  File "newRdvChecker.py", line 2, in <module>
    import requests

I'm running this setup on my Linux Mint computer, if that makes a difference


回答1:


Determine what exact python executable you use when running the script from CLI (with which python) and specify the full path to python in your crontab.



来源:https://stackoverflow.com/questions/50796215/running-python-script-through-crontab-cant-find-imports

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!