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:
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:
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:
3) When referencing files from the Python script, use the full path.
text = open(‘hn_source.html’, ‘r’).read()
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.