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

时间:2022-06-29 08:17:01

I try to start celery using command below:

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

celery -A converter worker --loglevel=info

but it doesn't work. my converter.py is:

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

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

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

and my celery.py:

和我的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))

but I get following error:

但我得到以下错误:

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'

Do anyone has any idea?Thank for help

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

2 个解决方案

#1


0  

Looks like your celery.py file shadows the celery package.

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

#2


0  

I've been experiencing a similar problem and I think the issue might be from where you're running celery -A proj worker --loglevel=info.

我一直遇到类似的问题,我认为这个问题可能来自你正在运行celery -A proj worker -loglevel = info。

If you have a project structure like

如果您有类似的项目结构

directory
--virtualenv/
--proj/
----manage.py
----requirements.txt
----proj/
------settings.py
------celery.py

You need to run the command from --proj/

你需要从--proj /运行命令

#1


0  

Looks like your celery.py file shadows the celery package.

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

#2


0  

I've been experiencing a similar problem and I think the issue might be from where you're running celery -A proj worker --loglevel=info.

我一直遇到类似的问题,我认为这个问题可能来自你正在运行celery -A proj worker -loglevel = info。

If you have a project structure like

如果您有类似的项目结构

directory
--virtualenv/
--proj/
----manage.py
----requirements.txt
----proj/
------settings.py
------celery.py

You need to run the command from --proj/

你需要从--proj /运行命令