73๐
Adding the following lines to cloud/celery.py:
import celery
print celery.__file__
gave me the file itself and not the celery module from the library. After renaming celery.py to celeryapp.py and adjusting the imports all errors were gone.
Note:
That leads to a change in starting the worker:
celery worker --app=cloud.celeryapp:app
For those running celery==3.1.2 and getting this error:
TypeError: unpack_from() argument 1 must be string or read-only buffer, not memoryview
Apply the patch mentioned here: https://github.com/celery/celery/issues/1637
51๐
With Django 1.7.5, Celery 3.1.17, and Python 2.7.6 I found that I was still getting these ImportError: cannot import name Celery
. But only when running tests under PyCharm 4.0.4.
I found that a solution was not to rely on from __future__ import absolute_import
as described in First Steps with Django. Instead I renamed proj/proj/celery.py
to proj/proj/celery_tasks.py
and then changed the content of __init__.py
to match: from .celery_tasks import app as celery_app
. No more multiple instances of files named celery.py
to cause import confusion seemed to be a simpler approach.
- [Django]-Django Rest Framework: Access item detail by slug instead of ID
- [Django]-Phpmyadmin logs out after 1440 secs
- [Django]-Django.db.migrations.exceptions.InconsistentMigrationHistory
17๐
got the same error
my celery settings filename which was(celery.py) was conflicting with โceleryโ packageโฆ
so while doing this-> from celery import Celery ,
it was raising error- cannot import name Celery
solution->just change the โcelery.pyโ to something else like โcelery-settings.pyโ
- [Django]-Django: OperationalError No Such Table
- [Django]-Django import error โ no module named django.conf.urls.defaults
- [Django]-How to compare two JSON objects with the same elements in a different order equal?
13๐
In October 2022, importlib-metadata==5.0.0
was released. In python 3.7, this breaks kombu==5.2.4
(see issue#1600) which is used by the current version of celery
.
Pin importlib-metadata==4.13.0
or another version less than 5, or update to python 3.8.
- [Django]-Redirect / return to same (previous) page in Django?
- [Django]-Programmatically saving image to Django ImageField
- [Django]-Django Queryset with filtering on reverse foreign key
9๐
Work for me ( some bug after deploy in server ):
Remove all *.pyc files from project and restart him.
- [Django]-OperationalError: database is locked
- [Django]-Django: How to create a model dynamically just for testing
- [Django]-Embed YouTube video โ Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
8๐
Did you add the line:
from __future__ import absolute_import
to the top of your cloud/celery.py
module?
Read the breakdown of the example here:
http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
- [Django]-How do I set up Jupyter/IPython Notebook for Django?
- [Django]-How do I return a 401 Unauthorized in Django?
- [Django]-OperationalError: database is locked
5๐
For someone who want to know what cause this error:
I have meet this problem just now, then I found the problem โ sys.path.
Maybe you add some path to sys.path like me, I add below code in manage.py,
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
SRC_PATH = os.path.join(ROOT_PATH, 'src')
CONF_PATH = os.path.join(ROOT_PATH, 'conf')
sys.path.insert(0, SRC_PATH)
sys.path.insert(0, CONF_PATH)
so, from celery import Celery
would search celery in SRC_PATH
and CONF_PATH
first, thatโs the problem.
change to
sys.path.append(SRC_PATH)
sys.path.append(CONF_PATH)
It would search in pythonโs lib
and site-packages
first. Solved perfectly.
- [Django]-Django REST framework post array of objects
- [Django]-How do I use django rest framework to send a file in response?
- [Django]-Django. You don't have permission to edit anything
4๐
I got the same error. It turns out there was a problem with my Celery version. I upgraded to 3.1 and celeryd is now deprecated for this version (http://celery.readthedocs.org/en/latest/whatsnew-3.1.html). So I had to downgrade to the version 3.0.19 that was the previous stable version used for the project, and it works good so far.
pip install celery==3.0.19
Anyway, if you donโt want to downgrade, the replacement for celeryd in the version 3.1 is celery worker. Check here for more info: http://celery.readthedocs.org/en/latest/userguide/workers.html.
Hope this helps! ๐
- [Django]-Docker/Kubernetes + Gunicorn/Celery โ Multiple Workers vs Replicas?
- [Django]-Suppress "?next=blah" behavior in django's login_required decorator
- [Django]-Convert an IP string to a number and vice versa
2๐
I have face similar type of issue:
from celery import Celery
ImportError: cannot import name โCeleryโ from โceleryโ
Another simple way to solve this:
If your package have celery configuration in celery.py this is the reason that it is causing problems.
Rename it something like celery_settings.py
- [Django]-Django 2, python 3.4 cannot decode urlsafe_base64_decode(uidb64)
- [Django]-How to group by AND aggregate with Django
- [Django]-What is pip install -q -e . for in this Travis-CI build tutorial?
1๐
Note that older Django projects have the manage.py
script in the same directory as the project directory. That is, the structure looks like this:
- proj/
- proj/__init__.py
- proj/celery.py
- proj/urls.py
- proj/manage.py
- proj/settings.py
instead of this:
- proj/
- proj/__init__.py
- proj/celery.py
- proj/settings.py
- proj/urls.py
- manage.py
In this case, you will just have to rename the celery.app
file to something different, like celeryapp.py
as suggested in the accepted answer above.
- [Django]-Automatic creation date for Django model form objects
- [Django]-How to do math in a Django template?
- [Django]-Django: Open uploaded file while still in memory; In the Form Clean method?
1๐
I faced the same issue on a FastAPI app running on Python 3.7. None of the solutions from this thread were working for me. I fixed the issue on my app by upgrading Python to 3.8.
- [Django]-How can I get the full/absolute URL (with domain) in Django?
- [Django]-Error: could not determine PostgreSQL version from '10.3' โ Django on Heroku
- [Django]-Images from ImageField in Django don't load in template
1๐
If the above error i.e. ImportError: cannot import name 'Celery' from 'celery' (/usr/local/airflow/.local/lib/python3.7/site-packages/celery/__init__.py)
is coming and the python version is being used as 3.7.*, then due to a bug in importlib-metadata
library because of its latest release.
So, to fix the above issue please use this version in your python dependencies list:
- pip install importlib-metadata==4.13.0
Alternately, if you are using Docker file to build the project, change the python version from 3.7 to 3.8 and it should work fine.
For me, it worked. Please use the below link for a detailed look:
- [Django]-How to write a unit test for a django view?
- [Django]-Django Rest Framework File Upload
- [Django]-Django 'Sites' Model โ what is and why is 'SITE_ID = 1'?
0๐
I got the same error.
Seems that from __future__ import absolute_import
DOES NOT work for Python 2.6.1, still not raising an error.
Upgraded to Python 2.7.5 and it just worked.
- [Django]-Django Rest Framework Conditional Field on Serializer
- [Django]-Django, creating a custom 500/404 error page
- [Django]-How to use MySQLdb with Python and Django in OSX 10.6?
0๐
In my django application I had the same error. Version Django 4, Celery 5. My my problem is that I run Celery from directory with file celery.py, but it is necessary from directory with manage.py.
Slava Ukraini!
- [Django]-How to assign items inside a Model object with Django?
- [Django]-Django ModelForm for Many-to-Many fields
- [Django]-How can I see the raw SQL queries Django is running?