从 crontab 运行 python 的问题 - “无效的 Python 安装" [英] Problem running python from crontab - "invalid Python installation"

查看:33
本文介绍了从 crontab 运行 python 的问题 - “无效的 Python 安装"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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/之前包含 /usr/binlocal/bin(这是典型的) - 所以在你的 cron 中,指定要使用哪个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆