2

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

2 Answers 2

10

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/

Sign up to request clarification or add additional context in comments.

1 Comment

For me your tip worked, I changed the working directory as you said and it worked. Thanks!
0

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

1 Comment

Well just don't name your file "celery.py" (and remove the. pyc file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.