如何解决ImportError:无法导入名称'Celery'?

时间:2016-06-19 17:20:06

标签: python-3.x nginx uwsgi django-celery

使用命令sudo uwsgi --ini /etc/uwsgi/apps-enabled/tagstore.conf启动服务器后出现以下错误。

*** Operational MODE: preforking ***
Traceback (most recent call last):
  File "./wsgi.py", line 21, in <module>
    application = get_wsgi_application()
  File "/home/ubuntu/apps/tagstore/venv/lib/python3.4/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup()
  File "/home/ubuntu/apps/tagstore/venv/lib/python3.4/site-packages/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/ubuntu/apps/tagstore/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
    self._setup(name)
  File "/home/ubuntu/apps/tagstore/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/ubuntu/apps/tagstore/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/ubuntu/apps/tagstore/tagstore/tagstore/__init__.py", line 3, in <module>
    from .celery import app as celery_app
  File "/home/ubuntu/apps/tagstore/tagstore/tagstore/celery.py", line 3, in <module>
    from celery import Celery
  File "./celery.py", line 3, in <module>
    from celery import Celery
ImportError: cannot import name 'Celery'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
spawned uWSGI master process (pid: 2574)
spawned uWSGI worker 1 (pid: 2576, cores: 1)
spawned uWSGI worker 2 (pid: 2577, cores: 1)

我的celery.py文件是:

from __future__ import absolute_import
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tagstore.settings')

from django.conf import settings

app = Celery('tagstore')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.conf.update(CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

我在virtualenv文件夹中安装了django-celery。请帮我解决问题,如果需要任何其他信息,请告诉我。

0 个答案:

没有答案