pythad pythad - 5 months ago 71
Python Question

Celery 'module' object has no attribute 'app' when using Python 3

I am going through Celery tutorial. They are using Python2 and I am trying to implement the same using python3.

I have 2 files: :

from celery import Celery

app = Celery(
'proj', broker='amqp://', backend='amqp://', include=['proj.tasks'])


if __name__ == '__main__':

and :

from celery_proj import app

def add(x, y):
return x + y

def mul(x, y):
return x * y

def xsum(numbers):
return sum(numbers)

When I try to run
celery -A proj worker -l info
I am getting :

Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/celery/app/", line 235, in find_app
found =
AttributeError: 'module' object has no attribute 'app'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/celery", line 11, in <module>
File "/usr/local/lib/python3.4/dist-packages/celery/", line 30, in main
File "/usr/local/lib/python3.4/dist-packages/celery/bin/", line 81, in main
File "/usr/local/lib/python3.4/dist-packages/celery/bin/", line 769, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python3.4/dist-packages/celery/bin/", line 309, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/", line 469, in setup_app_from_commandline = self.find_app(app)
File "/usr/local/lib/python3.4/dist-packages/celery/bin/", line 489, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/usr/local/lib/python3.4/dist-packages/celery/app/", line 240, in find_app
found = sym.celery
AttributeError: 'module' object has no attribute 'celery'

What am I doing wrong and how to fix this?


If you're using Python 3, you can use absolute imports via: from __future__ import absolute_import

Here's a sample from a recent Python 3, Django 1.7 app of mine:

from __future__ import absolute_import

import os
import django

from celery import Celery
from django.conf import settings

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_app.settings')

app = Celery('my_app')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)