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
How to Filter Only Printable Characters in a File on Bash (Linux) or Python
Why Does Loading the Libc Shared Library Have "'Libraryloader' Object Is Not Callable" Error
"Command Not Found" Using Line in Argument to Os.System Using Python
How to Install Writable Shared and User Specific Data Files with Setuptools
Using Python Subprocess.Call() to Launch an Ncurses Process
How to Run Python Script in Cron
How to Direct Output to a File When There Are Utf-8 Characters
How to Send Http Requests to Flask Server
How to Open Process Again in Linux Terminal
How to Install Python 3.6.5 on My Ubuntu 19.10 That Already Contains Python 3.7.5
How Remove Camera Preview to Raspberry Pi
Unicode Box Drawing Characters Not Printed in Ruby
Python Threading with Queue: How to Avoid to Use Join