简体   繁体   中英

Python script error with cron

I am trying to run a python script every hour with cron. This is everything I have in my crontab.

0 * * * * python /Users/jamesrusso/Documents/TorMeasure/TorMeasurementProject/getConsensus.py

But I get an error when it tries to run saying ImportError: No module named stem.descriptor . I have included #!/usr/local/bin/python in my python script. Does anyone know a way to fix this or need more info let me know

Most likely you have multiple Python versions installed in your machine. Change your cron line to include the full path:

0 * * * * /usr/local/bin/python /Users/jamesrusso/Documents/TorMeasure/TorMeasurementProject/getConsensus.py

There are some steps you can check:

Step 1:

$which python 
will give you location of python installed

step 2:

try to include 
#!/usr/bin/env python

step 3:

you can give the full path of python in your cronjob
0 * * * * /usr/local/bin/python /Users/jamesrusso/Documents/TorMeasure/TorMeasurementProject/getConsensus.py

step 4:

have you tested your script before inserting to cronjob, is it was working fine?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM