python from crontab

python from crontab

Posted by: bcantrell
Posted on: 2008-04-20 11:24:00

I have a python script that works great when I execute it manually through SSH. But when I set up a cronjob to run it, I get back this error every time.

ImportError: No module named django.core.management

I've tried setting up django via these two methods and got the same error message with each:
http://blog.capstrat.com/tags/crontab/
http://superjared.com/entry/django-and-crontab-best-friends/


Re: python from crontab

Posted by: sXi
Posted on: 2008-04-20 11:34:00

Have you tried indicating the full path to the module?


Re: python from crontab

Posted by: bcantrell
Posted on: 2008-04-20 11:37:00

Bear with me, I'm a Python newb.
the import statement looks like this now:
from django.core.management import setup_environ

how would I change that to include the full path??

Re: python from crontab

Posted by: bcantrell
Posted on: 2008-04-20 11:43:00

Thanks for you help, I just figured it out. I guess crontabs on dreamhost run without environment. I added this to the top of my script

import sys, os
sys.path.append(‘/home/username/django/django_projects’)
sys.path.append(‘/home/username/django/django_src’)

per a comment I found on this Blog:

http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/


hope this helps someone!

Tags: python scriptcrontabcronjobdjangossherror message