1

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

7
  • What do you get when you type python --version? Is it the same as /usr/local/bin/python? Commented Jan 31, 2016 at 6:17
  • it doesn't matter you have #!/usr/local/bin/python in script because you run python script. Use full path to Python in crontab. Commented Jan 31, 2016 at 6:17
  • its always better to use #!/usr/bin/env python Commented Jan 31, 2016 at 6:17
  • have you tested your script before inserting to cronjob, is ti was working fine? Commented Jan 31, 2016 at 6:18
  • python version gives me "Python 2.7.10" which is the same as when i use /usr/local/bin/python. Yes it works fine in terminal. What do you mean #!/usr/bin/env python is better? Should I put that in the python script Commented Jan 31, 2016 at 6:45

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

I feel like this might be the problem, will keep you posted when the script runs in 14 mins
1

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.