6

I have python 2.7 installed on my linux box, and I'm trying to schedule a python script via crontab. The script works fine from the command line, however when running via cron I get:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site.py", line 553, in <module>
    main()
  File "/usr/local/lib/python2.7/site.py", line 535, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/lib/python2.7/site.py", line 268, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/lib/python2.7/site.py", line 243, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/local/lib/python2.7/site.py", line 233, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/local/lib/python2.7/sysconfig.py", line 535, in get_config_var
    return get_config_vars().get(name)
  File "/usr/local/lib/python2.7/sysconfig.py", line 434, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/local/lib/python2.7/sysconfig.py", line 298, in _init_posix
    raise IOError(msg)
IOError: invalid Python installation: unable to open /usr/include/python2.7/pyconfig.h (No such file or directory)

I see that /usr/include/python2.7 does't exist, but /usr/local/include/python2.7/ does. Did I make a mistake while installing python?

1
  • This doesn't directly answer your question, but have you tried ActivePython 2.7 - which installs to /opt/ActivePython-2.7? Commented Mar 18, 2011 at 17:23

3 Answers 3

3

You probably just have 2 versions installed, one of which is broken. If your cron is just directly calling python instead of a specific path, your PATH probably contains /usr/bin before /usr/local/bin (which is typical) - so in your cron, specify which python to use, or remove the existing one in /usr/bin and symlink /path/to/good/python to /usr/bin/python.

Edit: scratch that, just re-read and saw that it works fine from the command line. python-dev is probably the way to go. Sorry!

Sign up to request clarification or add additional context in comments.

2 Comments

$PATH defines where the system looks for binaries, but I'm not sure if python can give out the location of it's headers via it's binary executable...
That was part of my misreading - I was saying that his cron was probably just using the wrong python binary because the wrong one was first in $PATH. Seeing that it works on the command line made that invalid. :)
2

You need python2.7-dev, which installs the includes and headers.

For Ubuntu, you run sudo apt-get install python2.7-dev to install it. What Linux distro are you running?

3 Comments

But Python works great from shell... It doesn't make sense that running it from crontab would require installing something else.
/usr/include/python2.7/pyconfig.h is a C++ header file. python2.7-dev installs the header files and other things that you need to be able to compile things using Python's C++ libraries, which is what your crontab thing is doing.
not likely; "import site" happens on Python startup. And here, something strange is going on with the sysconfig module on Ubuntu's Python. /usr/local's Python is reading /usr/'s include/ dirs ... that's not right.
2

I am assuming that in your crontab file, you are giving the full path to the python executable, and not just relying on she-bang with executable permissions. If not, please give point to the full-path python2.7 in the crontab file and also use the same full-path on the command line to ensure that you don't get this problem.If you get this on command line too, then it is probably missing some development headers. (Are you trying to compile something like using setup.py build and trying to do it via crontab?) I am trying to understand where would one need those headers. So, apart from the above suggestion, extra information from your end might ofcourse help further.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.