简体   繁体   中英

Django, ImportError: cannot import name Celery

Why is this happening?
My celery.py:

import os
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', 'myshop.settings')

app = Celery('myshop')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

my init .py

# import celery
from .celery import app as celery_app

I even tried renaming celery.py to something else and the error still persisted. Could it be because of my python version?

I`ll post answer in order to move it from comments.

First of all in your __ init__.py file add this line

from __future__ import absolute_import, unicode_literals

Second of all you need to add to your settings, information about brooker. This is an example configuration file to get you started. It should contain all you need to run a basic Celery set-up.

Broker settings.

broker_url = 'amqp://guest:guest@localhost:5672//'

The next thing is running your celery worker. So if you celery app is named myshop you have to run celery worker (using your environment), by typing this simple command:

celery -A myshop worker -l info

Then try to run your task, and everything should be fine.

its becuase of version

How u have installed celery

pip install celery==3.0.19
if this
then run python by
python manage.py runserver
or
pip3 install celery==3.0.19 if this
then run python by
python3 manage.py runserver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM