[Django]-Importing celery in project fails, works(sort of) in manage.py shell

5đź‘Ť

âś…

Try altering tasks.py to:

from __future__ import absolute_import
from celery import task

It’s possible that you have a celery/ or celery.py in the same directory as the module throwing the error (tasks.py), and this is failing as a relative import.

👤mik3y

1đź‘Ť

Yikes, where did you get all that in your first step?? I’ve never had to alter the manage.py or wsgi.py files to get additional packages running. You say “downloaded celery modules” and then you have all that sys.path alteration code. That leads me to believe you aren’t using pip and virtualenv. Your life will be massively easier using those two tools. You’ll simplify things so much your team will love you forever. Don’t over-complicate when Python package management exists to make this pain free. Path mangling is rarely necessary.

Those Celery first steps you reference are really all it takes. Looks like you’ve handled that special mod_wsgi note. My guess is the problem lies in the first step — whatever modifications you’ve made to manage.py and wsgi.py. All the other steps look fine*.

I’d make a copy of your code, make a new virtualenv, pip install those packages and remove all the path setup stuff. Use django-admin.py startproject xxx to see what plain vanilla manage.py and wsgi.py files look like. Also use DEBUG=True to help with the troubleshooting. When that works and you get things settled, replace your settings.ini with a pip requirements file.

* You use South so remember python manage.py migrate djcelery. (In your step 4 you only use syncdb). I don’t believe doing this will fix the import error but it’s necessary in the larger picture.

👤JCotton

Leave a comment