ImportError: cannot import name 'MyClass' from 'mymodule'
Python found the module but can’t find the specific name you’re trying to import.
Fix 1: Check for typos
# ❌ Wrong name
from flask import Flaskk
# ✅ Correct name
from flask import Flask
Check the module’s docs or source for the exact export name.
Fix 2: Circular imports
The most common cause. Two files import each other:
# a.py
from b import helper # b.py hasn't finished loading yet!
# b.py
from a import something # a.py hasn't finished loading yet!
Fixes:
- Move the import inside the function that uses it
- Restructure to break the cycle
- Move shared code to a third file
# ✅ Import inside function
def my_function():
from b import helper # Only imported when called
return helper()
Fix 3: Wrong package version
# The function might not exist in your installed version
pip show flask # Check version
pip install --upgrade flask
Fix 4: Name doesn’t exist in that module
# ❌ json doesn't have 'parse'
from json import parse
# ✅ It's called 'loads'
from json import loads
Check what’s available: import mymodule; print(dir(mymodule))
See also: Python ModuleNotFoundError fix | Python cheat sheet