Django管理命令Cron在Dotcloud上

时间:2012-05-04 03:10:52

标签: cron pythonpath dotcloud django-manage.py

我正在尝试运行一个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:/家庭/ dotcloud /电流:/home/dotcloud/env/lib/python2.6:/home/dotcloud/env/lib/python2.6/plat-linux2:/家庭/ 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

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

感谢。

1 个答案:

答案 0 :(得分:7)

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

而不是这样做:

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

你应该这样做:

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

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