5

I am following the Celery Documentation v:latest I installed all the dependencies and my celery version is 3.0.11 I made a file tasks.py and pasted the code:

from celery import Celery

app = Celery('tasks', broker='amqp://guest@localhost//')

@app.task
def add(x, y):
    return x + y

When I run the very Next command in the same directory:

celery -A tasks worker --loglevel=info

I get this error `AttributeError: 'module' object has no attribute 'celery'

I got few similar question but that did not helped me ... Do any one has any idea ? Here is the TraceBack...

Traceback (most recent call last):
  File "/home/nishant-un/env/bin/celery", line 9, in <module>
    load_entry_point('celery==3.0.11', 'console_scripts', 'celery')()
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/__main__.py", line 14, in main
    main()
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 946, in main
    cmd.execute_from_commandline(argv)
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/bin/celery.py", line 890, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/bin/base.py", line 177, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/bin/base.py", line 295, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/bin/base.py", line 313, in find_app
    return sym.celery
AttributeError: 'module' object has no attribute 'celery'
3
  • 3
    On what line do you get that AttributeError? Could you provide a full traceback please? Commented Nov 17, 2013 at 10:17
  • 1
    I had updated the traceback .. Commented Nov 17, 2013 at 11:15
  • Why are you using 3.0.11? Seems like you are using the example from Celery 3.1. You can always specify the full path to the app, which in your example would be: -A tasks:app This means the same as from tasks import app in a python module, and tells the celery command where to find the instance to use, the shortcut form did not work like this in the version you are using (3.0.11) Commented Nov 17, 2013 at 20:43

2 Answers 2

12

Running the following command from the root of my project, fixed this issue:

celery -A my_app.tasks worker --loglevel=info

Celery needed the path to the tasks.py file.

Sign up to request clarification or add additional context in comments.

Comments

6

Try replace your code with

celery = Celery('tasks', broker='amqp://guest@localhost//')

@celery.task
def add(x, y):
    return x + y

5 Comments

I did that But I am Getting another error after it starts: I am pasting it in breaks because it is too long. [2013-11-17 17:21:47,020: ERROR/MainProcess] Received unregistered task of type 'task.messagecleaner.clean_message'. The message has been ignored and discarded. Did you remember to import the module containing this task? Or maybe you are using relative imports? Please see http://bit.ly/gLye1c for more information.
Traceback (most recent call last): File "/home/nishant-un/env/local/lib/python2.7/site-packages/celery/worker/consumer.py", line 432, in on_task_received strategies[name](message, body, message.ack_log_error) KeyError: 'task.messagecleaner.clean_message'
@NishantKashyap do this error arise when you run task.add() task?
Your version is old, you should upgrade to 3.1
To expand on asksol's helpful comment, it appears that version of Celery prior to 3.1 required the Celery instance to be named exactly "celery", and OP's error is a result of this. This appears to have been changed in Celery 3.1, so it doesn't matter what you call your Celery instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.