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?

Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
ripper234
  • 222,824
  • 274
  • 634
  • 905

3 Answers3

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!

mway
  • 4,334
  • 3
  • 26
  • 37
  • `$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... – Blender Mar 17 '11 at 22:27
  • 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. :) – mway Mar 17 '11 at 22:28
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?

Blender
  • 289,723
  • 53
  • 439
  • 496
  • 1
    But Python works great from shell... It doesn't make sense that running it from crontab would require installing something else. – ripper234 Mar 18 '11 at 09:59
  • `/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. – Blender Mar 18 '11 at 14:34
  • 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. – Sridhar Ratnakumar Mar 18 '11 at 17:20
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.

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131