问题
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