24

/home/myuser/mysite-env/lib/python2.6/site-packages/celery/loaders/default.py:53: NotConfigured: No celeryconfig.py module found! Please make sure it exists and is available to Python.
NotConfigured)

I even defined it in my /etc/profile and also in my virtual environment's "activate". But it's not reading it.

Sebastian
  • 1,055
  • 9
  • 27
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
  • 2
    Stupid question... (because I've done this) when python executes is it running the correct version. I've worked on systems with 2 versions of python... don't ask. – John Giotta Jan 21 '11 at 19:47

4 Answers4

39

Now in Celery 4.1 you can solve that problem by that code(the easiest way):

import celeryconfig

from celery import Celery

app = Celery()
app.config_from_object(celeryconfig)

For Example small celeryconfig.py :

BROKER_URL = 'pyamqp://'
CELERY_RESULT_BACKEND = 'redis://localhost'
CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}

Also very simple way:

from celery import Celery

app = Celery('tasks')

app.conf.update(
    result_expires=60,
    task_acks_late=True,
    broker_url='pyamqp://',
    result_backend='redis://localhost'
)

Or Using a configuration class/object:

from celery import Celery

app = Celery()

class Config:
    enable_utc = True
    timezone = 'Europe/London'

app.config_from_object(Config)
# or using the fully qualified name of the object:
#   app.config_from_object('module:Config')

Or how was mentioned by setting CELERY_CONFIG_MODULE

import os
from celery import Celery

#: Set default configuration module name
os.environ.setdefault('CELERY_CONFIG_MODULE', 'celeryconfig')

app = Celery()
app.config_from_envvar('CELERY_CONFIG_MODULE')

Also see:

Sergey Luchko
  • 2,996
  • 3
  • 31
  • 51
  • How to do it when you have just the filename? /path/to/filename.py – 101010 Dec 15 '16 at 04:23
  • @010110110101 First option seems to be right for you. See in the answer I have added some explanation for first option. If it isn't clear I'm ready to help. – Sergey Luchko Dec 15 '16 at 20:16
  • To make it even easier the calls to `config_from_object` can be omitted by setting the config directly on `Celery()` using the keyword argument `config_source` i.e. `app = Celery(config_source=celeryconfig)` – Vikas Prasad Aug 13 '18 at 10:40
22

I had a similar problem with my tasks module. A simple

# celery config is in a non-standard location
import os
os.environ['CELERY_CONFIG_MODULE'] = 'mypackage.celeryconfig'

in my package's __init__.py solved this problem.

Sebastian
  • 1,055
  • 9
  • 27
  • As recommended in [Celery's recommendations for Django](http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html), `os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')` in the celery configuration file before `app = Celery('tasks')` is called should work well, especially if you wanted to update your settings file dynamically later. – Nick Merrill Jun 20 '14 at 01:27
3

Make sure you have celeryconfig.py in the same location you are running 'celeryd' or otherwise make sure its is available on the Python path.

harry
  • 1,061
  • 1
  • 13
  • 13
3

you can work around this with the environment... or, use --config: it requires

  1. a path relative to CELERY_CHDIR from /etc/defaults/celeryd
  2. a python module name, not a filename.

The error message could probably use these two facts.

fastmultiplication
  • 2,951
  • 1
  • 31
  • 39