我有一个Python驱动程序和库脚本,它们是兄弟:
/home/mydir/pythonProjs/
driver.py
lib.py
在driver.py
中,我有一行:
from lib import method1
我在Linux上的命令行中成功执行了以下操作:
python /home/mydir/pythonProjs/driver.py
但当我在crontab中尝试以下操作时:
10 1 * * * export PYTHONPATH=~/mydir/pythonProjs; python /home/mydir/pythonProjs/driver.py
我知道错误:
ImportError: No module named lib.method1
我还尝试将crontab命令中的路径设置更改为完全限定的路径/home/mydir/pythonProjs
,省略“导出”,并尝试写入.sh文件(带有必要的#!垃圾箱/垃圾桶……)
我有一个主要问题和一个后续问题: 梅因:什么是解决我问题的最佳实践方法? 后续:cron拥有与我的shell不同的路径访问,其背后的理念是什么?
在我很快投票之前,我会提到我读过但没有成功(或正确分析过)以下内容: -Where can I set environment variables that crontab will use? -Crontab Issues running Python -http://pythonadventures.wordpress.com/2012/03/31/calling-a-python-script-from-crontab/
尝试从虚拟作业中打印出环境变量
如https://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work所示
还要检查shell crontab使用的是什么。您可以通过添加一行将
$SHELL
环境变量设置为bash
SHELL=/bin/bash
在crontab文件的开头。
相关问题 更多 >
编程相关推荐