Problem Running Python from Crontab - "Invalid Python Installation"

Crontab wont run python script

Add

#!/usr/bin/env python

to the beginning of your script - right now it's trying to execute your script as a bash, that line says "I'm a python script, please use the right interpreter". It's also called a hash-bang line, but it needs to be the first line in your script.

Ubuntu 11.10 + Bash + Python error + Invalid python installation

After a lot of discussion and help from ppl on irc!

As one of the comments to the questions have suggested, the main instruction that was suggested by many ppl was

apt-get install --reinstall packagename

but it did not really seem to help.

So i simply downloaded python2.7-minimal_2.7.2-5ubuntu1_amd64.deb from the ubuntu package sites and

$ sudo dpkg -i python2.7-minimal_2.7.2-5ubuntu1_amd64.deb

voila it worked! once you finish that, make sure you update!

Crontab using incorrect version of Python to run script

If you have a separate version of python installed for 2.7 you can look for it with whereis python

I have CentOS 6 which comes with 2.6 by default, so this command returns:

python2: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python2 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/lib/python2.7 /usr/include/python2.6

Of these /usr/local/bin/python2.7 is the one I'm interested in, so when I put a job in crontab, I choose it explicitly:

30 00 * * * /usr/local/bin/python2.7 /home/mike/job.py


Related Topics



Leave a reply



Submit