从crontab运行python时出现问题-“无效的python安装" [英] Problem running python from crontab - "invalid Python installation"
问题描述
我在linux机器上安装了python 2.7,我正在尝试通过crontab计划python脚本.该脚本可以从命令行正常运行,但是通过cron运行时,我得到了:
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)
我看到/usr/include/python2.7
不存在,但是/usr/local/include/python2.7/
存在.安装python时,我是否犯了一个错误?
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?
推荐答案
您可能只安装了2个版本,其中一个版本已损坏.如果您的cron只是直接调用python
而不是特定路径,则您的PATH
可能在/usr/local/bin
之前包含/usr/bin
(这是典型的)-因此在您的cron中,指定要使用的python或删除现有的python /usr/bin
中的一个,并将/path/to/good/python
链接到/usr/bin/python
.
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
.
从头开始,只需重新阅读并在命令行中看到它正常工作即可. python-dev
可能是要走的路.抱歉!
scratch that, just re-read and saw that it works fine from the command line. python-dev
is probably the way to go. Sorry!
这篇关于从crontab运行python时出现问题-“无效的python安装"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!