[Solved]-ImportError: cannot import name 'Celery' from 'celery'

20๐Ÿ‘

I had this exact same issue the way you described, and it started happening only recently (CI failed Oct 3, 2022 but worked fine Sep 25, 2022, with no related changes in between).

What ended up being the cause was the fact that in my CI, importlib-metadata started installing version 5.0.0, which gave the error (Worked fine with 4.12.0).

To fix it for now, I just added importlib-metadata==4.13.0 to my environment.yml file, after which the issue was solved.

๐Ÿ‘คUlm

4๐Ÿ‘

https://github.com/python/importlib_metadata/issues/411

Downgrade importlib-metadata to 4.13.0.

๐Ÿ‘คBeichen Ou

0๐Ÿ‘

A shorten Answer:
Your problem here is that youโ€™ve named a submodule (aka a python file)
or a package (aka a folder) with the same name of the package that you want to import celery therefore you need to change the name of this file in order to import the correct package.

More details:
Python importing module checks the packages name in the paths specified ordered in sys.path. So if you printed

print(sys.path)

You will get a list of paths at where the interpreter will start to search for the package name in the same order, and the first path is your current directory path so once it finds it in your current working directory it will import it and wouldnโ€™t continue searching.

for more details you can read the documentation from here

๐Ÿ‘คMohamed Mostafa

0๐Ÿ‘

Install it by placing your cursor on red underline and then select install pkg or press alt+shift+enter

๐Ÿ‘คAwais Imran

Leave a comment