gpt4 book ai didi

python - celery worker 错误 : ImportError no module named celery

转载 作者:IT老高 更新时间:2023-10-28 22:20:07 26 4
gpt4 key购买 nike

我在尝试启动 celery worker 时遇到导入错误。我不确定问题是什么。任何帮助将不胜感激。

我的项目:

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)

最佳答案

问题是你在说“嘿,兄弟,我听说你喜欢 celery ,吃点 celery ”。

但实际上你应该说,“嘿,兄弟,我听说你安装了 celery,让我们创建一个名称非常相似的文件,这样我们就不会混淆我们的环境”。 p>

将您的 email/celery.py 文件重命名为 email/celery_app.py

然后,当您启动您的工作人员时,请执行以下操作:

celery -A email worker --app=email.celery_app:app --loglevel=info # etc.

关键是你需要在你的文件结构中包含名为 celery.py 的文件,但如果你没有,那么你就不能依赖 celery 找到 celery,所以必须手动指定 --app 来指向它。

关于python - celery worker 错误 : ImportError no module named celery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19577172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com