Starting Celery: AttributeError: 'module' object has no attribute 'celery'


I try to start a Celery worker server from a command line:

celery -A tasks worker --loglevel=info

The code in

import os
os.environ[ 'DJANGO_SETTINGS_MODULE' ] = "proj.settings"

from celery import task

def add_photos_task( lad_id ):

I get the next error:

Traceback (most recent call last):
  File "/usr/local/bin/celery", line 8, in <module>
    load_entry_point('celery==3.0.12', 'console_scripts', 'celery')()
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/", line 14, in main
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/", line 946, in main
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/", line 890, in execute_from_commandline
    super(CeleryCommand, self).execute_from_commandline(argv)))
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/", line 177, in execute_from_commandline
    argv = self.setup_app_from_commandline(argv)
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/", line 295, in setup_app_from_commandline = self.find_app(app)
  File "/usr/local/lib/python2.7/site-packages/celery-3.0.12-py2.7.egg/celery/bin/", line 313, in find_app
    return sym.celery
AttributeError: 'module' object has no attribute 'celery'

Does anybody know why the 'celery' attribute cannot be found? Thank you for help.

The operating system is Linux Debian 5.

Edit. May be the clue. Could anyone explain me the next comment to a function (why we must be sure that it finds modules in the current directory)?

# from celery/utils/
def import_from_cwd(module, imp=None, package=None):
    """Import module, but make sure it finds modules
    located in the current directory.

    Modules located in the current directory has
    precedence over modules located in `sys.path`.
    if imp is None:
        imp = importlib.import_module
    with cwd_in_path():
        return imp(module, package=package)
11/26/2012 10:57:25 AM

Accepted Answer

I forgot to create a celery object in

from celery import Celery
from celery import task  

celery = Celery('tasks', broker='amqp://guest@localhost//') #!

import os

os.environ[ 'DJANGO_SETTINGS_MODULE' ] = "proj.settings"

def add_photos_task( lad_id ):

After that we could normally start tasks:

celery -A tasks worker --loglevel=info
11/26/2012 4:36:41 PM

Celery uses celery file for storing configuration of your app, you can't just give a python file with tasks and start celery. You should define celery file ( for Celery>3.0; previously it was

celeryd --app app.celery -l info

This example how to start celery with config file at app/

Here is example of celery file:

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow