当我尝试启动我的芹菜工人时,我收到导入错误。我不确定是什么问题。任何帮助将受到高度赞赏。
我的项目:
email/__init__.py
/celery.py
我尝试通过调用:
来运行应用程序celery worker --app=email
我已按照此处的所有步骤进行操作 - http://docs.celeryproject.org/en/latest/getting-started/next-steps.html#about-the-app-argument
追溯:
File "/Users/.../bin/celery", line 9, in <module>
load_entry_point('celery==3.0.24', 'console_scripts', 'celery')()
File "/Users/.../lib/python2.7/site-packages/celery/__main__.py, line 14, in main
main()
File "/Users/.../lib/python2.7/site-packages/celery/bin/celery.py", line 957, in main
cmd.execute_from_commandline(argv)
File "/Users/.../lib/python2.7/site-packages/celery/bin/celery.py", line 901, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Users/.../lib/python2.7/site-packages/celery/bin/base.py", line 185, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/Users/.../lib/python2.7/site-packages/celery/bin/base.py", line 300, in setup_app_from_commandline
self.app = self.find_app(app)
File "/Users/.../lib/python2.7/site-packages/celery/bin/base.py", line 317, in find_app
return self.find_app('%s.celery:' % (app.replace(':', ''), ))
File "/Users/.../lib/python2.7/site-packages/celery/bin/base.py", line 311, in find_app
sym = self.symbol_by_name(app)
File "/Users/.../lib/python2.7/site-packages/celery/bin/base.py", line 322, in symbol_by_name
return symbol_by_name(name, imp=import_from_cwd)
File "/Users/.../lib/python2.7/site-packages/kombu/utils/__init__.py", line 80, in symbol_by_name
module = imp(module_name, package=package, **kwargs)
File "/Users/.../lib/python2.7/site-packages/celery/utils/imports.py", line 99, in import_from_cwd
return imp(module, package=package)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named celery
这是我的celery.py
from __future__ import absolute_import
from celery import Celery
from app import mail
celery = Celery('email.celery',
broker = 'amqp://guest:guest@localhost:5672//',
backend = 'amqp://')
if __name__ == '__main__':
celery.start()
@celery.task
def send_email(nickname, email):
mail.send(msg)
答案 0 :(得分:42)
问题在于你说'#em>嘿嘿兄弟我听说你喜欢芹菜有一些芹菜&#34;。
但实际上你应该说,&#34; 嘿兄弟我听说你安装芹菜,让我们制作一个名字非常相似的文件,这样我们就不会把我们的环境搞得一团糟&#34;
将您的email/celery.py
文件重命名为email/celery_app.py
然后,当您启动工作人员时,请执行以下操作:
celery -A email worker --app=email.celery_app:app --loglevel=info # etc.
关键是您需要不在您的文件结构中包含名为celery.py
的文件,但如果您不这样做,则您无法依赖在芹菜上寻找芹菜,所以你必须通过手动指定--app来指出它。
答案 1 :(得分:21)
我实际上遇到了类似的问题,假设您正在关注Next Steps tutorial,我必须做的就是解决问题,只需从 proj 上面的目录中运行该工作人员,即,假设您当前在 proj 目录中运行:
cd ..
celery -A proj worker -l info
现在它对我有用。