2

我正在尝试运行 cron 来运行自定义 Django 管理命令。我在 DotCloud 上运行。

当 cron 运行时,我收到以下错误:

Traceback (most recent call last):
File "./manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named django.core.management

我认为这是因为 cron 在裸环境中运行,所以我尝试在同一个 cron 中手动设置 PYTHONPATH。这是那个命令...

PYTHONPATH=/home/dotcloud/env/lib/python2.6/site-packages/setuptools-0.6c11-    
py2.6.egg:/home/dotcloud/env/lib/python2.6/site-packages/pip-1.0.1-        

py2.6.egg:/home/dotcloud/current:/home/dotcloud/env/lib/python2.6:/home/dotcloud/env/lib/python2.6/plat-linux2:/home/dotcloud/env/ lib/python2.6/lib-tk:/home/dotcloud/env/lib/python2.6/lib-old:/home/dotcloud/env/lib/python2.6/lib-dynload:/usr/lib/python2 .6:/usr/lib64/python2.6:/usr/lib/python2.6/plat-linux2:/usr/lib/python2.6/lib-tk:/usr/lib64/python2.6/lib-tk :/home/dotcloud/env/lib/python2.6/site-packages:/usr/local/lib/python2.6/dist-packages/virtualenv-1.6.1-py2.6.egg:/usr/local/ lib/python2.6/site-packages:/usr/local/lib/python2.6/dist-packages:/usr/lib/python2.6/dist-packages:/usr/lib/pymodules/python2.6

错误仍在发生,我不确定发生了什么。非常感谢任何建议。

谢谢。

4

1 回答 1

7

你是对的:cron 作业在“裸”环境中运行。

而不是这样做:

* * * * * /home/dotcloud/current/myapp/manage.py args...

你应该做这个:

* * * * * /home/dotcloud/env/bin/python /home/dotcloud/current/myapp/manage.py args...

运行包含的python解释器~/env/bin将自动设置正确的环境。

于 2012-05-04T03:37:33.933 回答