gpt4 book ai didi

python - Django Celery 设置导入问题

转载 作者:太空狗 更新时间:2023-10-30 02:04:07 25 4
gpt4 key购买 nike

我正在尝试创建一个 celery 文件并通过 .. 运行它

celery -A myapp worker -l info

但是我得到了错误,

  File "/production/pythonenv/project/lib/python2.7/site-packages/configurations/base.py", line 30, in __new__
raise ImproperlyConfigured(install_failure)
django.core.exceptions.ImproperlyConfigured: django-configurations settings importer wasn't correctly installed. Please use one of the starter functions to install it as mentioned in the docs: http://django-configurations.readthedocs.org/

这是配置/文件,

(通过'tree myapp/config/'从项目rool运行)

config/
|-- __init__.py
|-- __init__.pyc
|-- celery.py
|-- settings.py
|-- urls.py
|-- wsgi.py
myapp/
|-- __init__.py
|-- __init__.pyc
|-- celery.py
|-- helper.py
|-- models.pyc
|-- serializers.py
|-- views.py

celery.py

from __future__ import absolute_import
import os,sys,
from celery import Celery
from django.conf import settings

sys.path.append('/prod/project/')
sys.path.append('/prod/')

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')

app = Celery('myapp.celery.celery')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(settings.INSTALLED_APPS, related_name='tasks')

有什么想法吗?

最佳答案

根据 http://django-configurations.readthedocs.org/en/latest/cookbook/#celery您可能需要在 celery.py 中添加:

os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')

from configurations import importer
importer.install()

app = Celery('myapp.celery.celery')

关于python - Django Celery 设置导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23885836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com