What does ImportError cannot import name mean in Python?
Typical causes
The line from module import name fails when the module does not define that name. This can happen when a function was renamed or removed in a newer library version, or when the name lives in a submodule and you imported the wrong path.
A circular import is another common cause. If file A imports from file B while B is still loading and imports from A, the name may not be defined yet. The error message names the missing item, which helps you check the source.
- Check the spelling and capitalization of the name
- Compare the library version to the docs you are reading
- Look for two files that import each other
How to fix it
Confirm the name exists by opening the module file or checking its documentation. Installing the version the tutorial uses can also help when the API changed. Virtual environments sometimes hold an older package, so check which version is active.
For circular imports, move shared code into a third module, or import the module itself and access the name inside a function instead of at the top of the file.
When a library is typed with any or has missing type definitions, the compiler may behave differently than you expect. Installing the matching type package often resolves similar errors.
Common mistakes
- Installing a different package with the same name as the one you meant.
- Ignoring a stale virtual environment that still has an older library version.

Related questions
- What does NameError: name is not defined mean in Python?
- How do I fix ReferenceError: x is not defined in JavaScript?
- What does UnboundLocalError mean in Python?
- Why do I get a cannot find symbol error in Java?
- What does undefined reference to mean in C++?
- How do I fix a module not found error in Node.js?