crontab is using version 2.6 to run a script that requires 2.7 to run. How do I set the default version of Python to be 2.7 permanently? running ./file.py works fine, its just when its run through crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*,30 * * * * root /root/file.py >>/tmp/log.txt 2>&1
edit issue resolved
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/python
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*,30 * * * * root /usr/local/bin/python2.7 /root/file.py >>/tmp/log.txt 2>&1
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
Update the shebang of your Python script to use Python 2.7 explicitly:
#!/usr/bin/env python2.7
This first line tells Unix which interpreter to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With