I had a simple goal: run a python script every 15 minutes throughout the day. I read up on cron and expected to move on to the next task in no time…
Four frustrating hours later, I nailed it down:
For those of you Googling for a solution, here it is:
crontab -e:
Some pointers:
1) Use the full path to the Python interpreter.
2) Make sure the path is to the correct Python interpreter.
Some of the third party modules my script imported weren’t loading because my script was looking in the wrong place.
For example, one of my earlier attempts I tried using:
/usr/bin/python
But that interpreter wasn’t the same as the one I normally get when I simply type “python” at the terminal. The correct one for me is located at:
/Library/Frameworks/Python.framework/Versions/2.5/bin/python
3) When referencing files from the Python script, use the full path.
Bad:
text = open(‘hn_source.html’, ‘r’).read()
Good:
text = open(‘/Users/Matt/Programming/python/tests/hn_source.html’, ‘r’).read()
Bottom line: When using cron, ensure that you explicitly declare where everything is located.
Seems obvious in hindsight, but thanks!
My problem was 3. I wasn’t explicit in the python script. Thanks so much!
Thank you!!!!! Saved me