简体   繁体   中英

AttributeError: 'module' object has no attribute 'celery'

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'

Try replace your code with

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM