22

/home/myuser/mysite-env/lib/python2.6/site-packages/celery/loaders/default.py:53:未配置:未找到 celeryconfig.py 模块!请确保它存在并且对 Python 可用。
未配置)

我什至在我的 /etc/profile 以及我的虚拟环境的“激活”中定义了它。但它不是在读它。

4

4 回答 4

32

现在在 Celery 4.1 中,您可以通过该代码解决该问题(最简单的方法):

import celeryconfig

from celery import Celery

app = Celery()
app.config_from_object(celeryconfig)

例如小celeryconfig.py

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

也很简单的方法:

from celery import Celery

app = Celery('tasks')

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

或使用配置类/对象:

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')

或者通过设置 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')

另见:

于 2016-11-27T16:41:12.410 回答
21

我的任务模块也有类似的问题。一个简单的

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

在我的包裹中__init__.py解决了这个问题。

于 2011-08-07T14:03:03.583 回答
2

你可以在环境中解决这个问题......或者,使用 --config: 它需要

  1. /etc/defaults/celeryd 中相对于 CELERY_CHDIR 的路径
  2. python 模块名称,而不是文件名。

错误消息可能使用这两个事实。

于 2011-12-21T10:10:02.487 回答
2

确保在运行“celeryd”的同一位置有 celeryconfig.py,或者确保它在 Python 路径上可用。

于 2011-04-04T04:42:09.257 回答