close

[Solved] ImportError: Cannot import name X

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ImportError: Cannot import name X in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ImportError: Cannot import name X Error Occurs?

Today I get the following error ImportError: Cannot import name X in python.

How To Solve ImportError: Cannot import name X Error ?

  1. How To Solve ImportError: Cannot import name X Error ?

    To Solve ImportError: Cannot import name X Error The confusing part is that PyCharm will autocomplete the import in the console, but the import then fails.

  2. ImportError: Cannot import name X

    To Solve ImportError: Cannot import name X Error The confusing part is that PyCharm will autocomplete the import in the console, but the import then fails.

Solution 1

In my case, I was working in a Jupyter notebook and this was happening due the import already being cached from when I had defined the class/function inside my working file.

I restarted my Jupyter kernel and the error disappeared.

Solution 2

Also not directly relevant to the OP, but failing to restart a PyCharm Python console, after adding a new object to a module, is also a great way to get a very confusing ImportError: Cannot import name ...

The confusing part is that PyCharm will autocomplete the import in the console, but the import then fails.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read