芹菜错误:'模块'对象没有属性' celery'

时间:2017-08-21 06:03:56

标签: django celery

我尝试使用以下命令启动芹菜:

celery -A converter worker --loglevel=info

但它不起作用。 我的converter.py是:

from __future__ import absolute_import, unicode_literals
from celery.task import task

@task
def ffmpeg_convert(input_file, bitrate):
    #do something

和我的celery.py:

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.base')

app = Celery('converter')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_url = 'redis://localhost:6379/0'
app.autodiscover_tasks()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

但我收到以下错误:

Traceback (most recent call last):
  File "/usr/local/bin/celery", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 14, in main
_main()
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 326, in main
    cmd.execute_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 488, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 279, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 481, in setup_app_from_commandline
    self.app = self.find_app(app)
  File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 503, in find_app
    return find_app(app, symbol_by_name=self.symbol_by_name)
  File "/usr/local/lib/python2.7/dist-packages/celery/app/utils.py", line 366, in find_app
    found = sym.celery
AttributeError: 'module' object has no attribute 'celery'

有人有任何想法吗?感谢您的帮助

2 个答案:

答案 0 :(得分:3)

我一直遇到类似的问题,我认为问题可能出在您正在运行celery -A proj worker --loglevel=info的位置。

如果你有像

这样的项目结构
directory
--virtualenv/
--proj/
----manage.py
----requirements.txt
----proj/
------settings.py
------celery.py

您需要从--proj/

运行命令

答案 1 :(得分:0)

看起来你的celery.py文件会影响芹菜包。