mahnooosh
mahnooosh

Reputation: 75

celery error :'module' object has no attribute 'celery'

I try to start celery using command below:

celery -A converter worker --loglevel=info

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

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:

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

Upvotes: 2

Views: 4384

Answers (2)

HenryM
HenryM

Reputation: 5793

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.

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/

Upvotes: 10

bruno desthuilliers
bruno desthuilliers

Reputation: 77892

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

Upvotes: 0

Related Questions