【发布时间】:2015-09-14 13:31:54
【问题描述】:
crontab 正在使用 2.6 版本来运行需要 2.7 才能运行的脚本。如何将 Python 的默认版本永久设置为 2.7? 运行 ./file.py 工作正常,它只是通过 crontab 运行时
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*,30 * * * * root /root/file.py >>/tmp/log.txt 2>&1
编辑 问题已解决
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin/python
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
*,30 * * * * root /usr/local/bin/python2.7 /root/file.py >>/tmp/log.txt 2>&1
【问题讨论】:
-
你的环境是否安装了python 2.7?
-
是的,我可以运行 ./file.py 很好,只是当它通过 crontab 运行时它是一个问题
-
python2.7安装在哪里?
-
在你的 shell 类型中确定 python 并使用路径并将其添加为 PATH 变量中的第一个路径
-
在命令行尝试
which python和which python2.7。
标签: python python-2.7 crontab