我正在关注Celery文档v:latest
我安装了所有依赖项,我的celery版本是3.0.11
我创建了一个文件tasks.py并粘贴了代码:
from celery import Celery
app = Celery('tasks', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
当我在同一目录中运行next命令时:
celery -A tasks worker --loglevel=info
我收到此错误`AttributeError:'module'对象没有属性'celery'
我几乎没有类似的问题,但这对我没有帮助...... 有人有任何想法吗? 这是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'
答案 0 :(得分:6)
尝试用
替换代码celery = Celery('tasks', broker='amqp://guest@localhost//')
@celery.task
def add(x, y):
return x + y
答案 1 :(得分:4)
从项目的根目录运行以下命令,修复了此问题:
celery -A my_app.tasks worker --loglevel=info
Celery需要tasks.py
文件的路径。