Вопрос

I'm trying to run a cron to run a custom Django management command. I'm running on DotCloud.

When the cron runs, I get the following error:

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

I think this is because cron is running in a bare environment, so I tried to manually set the PYTHONPATH in the same cron. Here is that command...

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

The error is still occurring and I'm not sure what's going on. Any advice is much appreciated.

Thanks.

Это было полезно?

Решение

You're right: cron jobs run in a "bare" environment.

Instead of doing this:

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

You should do this:

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

Running the python interpreter contained in ~/env/bin will automatically setup the correct environment.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top