WebFaction
Community site: login faq
0
1

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

#!/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 21 Oct '12, 06:57

diegocepr
122
accept rate: 0%

edited 22 Oct '12, 10:39

seanf
12.2k41836


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

#!/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:

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.

permanent link

answered 21 Oct '12, 08:01

valentini
2614
accept rate: 28%

edited 22 Oct '12, 10:40

seanf
12.2k41836

Your answer
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×81
×52
×50

question asked: 21 Oct '12, 06:57

question was seen: 3,807 times

last updated: 22 Oct '12, 10:40

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM