Django Celery app - no module named celery error

I created a django-celery application, as in the tutorial:

http://docs.celeryproject.org/en/master/django/first-steps-with-django.html

Everything works fine when I run it without an application parameter, as in:

$ python manage.py celery worker -l info 

but I can not start it at all with the application parameter, as in:

 $ python manage.py celery worker -A myapp -l info 

where myapp is the name given to the application when I created the project with:

 $ python manage.py startapp myapp 

The error I get is:

 ImportError: No module named celery 

Does anyone know why this is happening and how to solve it?

+7
source share
2 answers

Edit April 2014:

Celery docs updated for version 3.1; the solution below is deprecated, see:

http://docs.celeryproject.org/en/master/django/first-steps-with-django.html


By default, celery searches for a module named celery.py to find its configuration. You can force celery to use a different name than celery.py by specifying it in the application argument - in this example we will look for celery config in settings.py :

 python manage.py celery worker --app=myapp.settings 

When using django-celery you can use the above call to start celery or do what I originally did and create celery.py in my celery.py application package:

 from settings import celery 

My Django settings.py contains the usual celery configuration:

 from celery import Celery celery = Celery(broker="amqp://guest: guest@127.0.0.1 :5672//") celery.conf.update( CELERY_DEFAULT_QUEUE = "myapp", CELERY_DEFAULT_EXCHANGE = "myapp", CELERY_DEFAULT_EXCHANGE_TYPE = "direct", CELERY_DEFAULT_ROUTING_KEY = "myapp", ) 

Then run the celery worker as follows:

 python manage.py celery worker --app=myapp 

Just for clarity, here is my complete application structure:

 myproject/ manage.py myapp/ __init__.py settings.py celery.py 
+14
source

Make sure that you are trying to start the celery worker from a directory that has access to the celery module. In my case, I tried to start the worker from the application directory, not the project.

0
source

All Articles