login community faq
0
1

I am using this script to check I can run it in python2.7.

1
2
3
4
#!/usr/bin/env python2.7
import sys
if __name__ == "__main__":
    print(sys.version)

The script I want to run can not run on python < 2.7

The Crontab line is */1 * * * * $HOME/bin/pythver.py > $HOME/bin/version.txt

It runs if #!/usr/bin/env python2.6 but it does not in any other version.

Can anybody hel me, please?

asked Oct 21 '12 at 06:57

diegocepr's gravatar image

diegocepr
1

edited Oct 22 '12 at 10:39

seanf's gravatar image

seanf ♦♦
56291220


The short answer is: specify the full path to python2.7 in your script, as in

1
#!/usr/bin/env /usr/local/bin/python2.7

Explanation:

The issue here is that crond will run a script a minimal environment set, thus /usr/local/bin is not in the PATH, hence the python2.7 binary is not found (or any other python version besides 2 and 2.6). You get a minimal environment when running scripts from crond:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
SHELL=/bin/sh
MAILTO=
USER=XXXXXX
PATH=/usr/bin:/bin
PWD=/home/XXXXXX
SHLVL=1
HOME=/home/XXXXXX
LOGNAME=XXXXXX
MAILFROM=X@XXXXXX.webfaction.com
_=/usr/bin/env

If you are relying on environmental variables, then you might need to set them explicitly in your script.

Sincerely,

Valentin I.

answered Oct 21 '12 at 08:01

valentini's gravatar image

valentini ♦♦
863

edited Oct 22 '12 at 10:40

seanf's gravatar image

seanf ♦♦
56291220

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×228
×50
×37
×21

Asked: Oct 21 '12 at 06:57

Seen: 290 times

Last updated: Oct 22 '12 at 10:40

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited