我正在关注Celery文档v:latest
我安装了所有的依赖项,我的芹菜版本是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"对象没有属性"芹菜"
我几乎没有得到类似的问题,但这对我没有帮助。。。有人知道吗?这是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'
从我的项目根运行以下命令,修复了这个问题:
celery -A my_app.tasks worker --loglevel=info
Celery需要tasks.py
文件的路径。
尝试用替换您的代码
celery = Celery('tasks', broker='amqp://guest@localhost//')
@celery.task
def add(x, y):
return x + y