python
import_error
ai_generated
true
AttributeError: module 'X' has no attribute 'Y'
ID: python/attributeerror-module-no-attribute
92%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Module imported but attribute doesn't exist. Common: file named same as module (shadowing).
genericWorkarounds
-
95% success Check if you have a local file named same as the module: ls *.py | grep <module>
# e.g., having 'random.py' shadows stdlib random module
Sources: https://docs.python.org/3/reference/import.html#the-module-search-path
-
88% success Check the module version — attribute may have been added/removed in an update
python -c 'import module; print(module.__version__)'
Sources: https://docs.python.org/3/library/importlib.metadata.html
Dead Ends
Common approaches that don't work:
-
Reinstall the package
65% fail
Usually not a package issue — it's a naming conflict in your project
-
Use importlib to force reimport
70% fail
Reimporting doesn't fix shadowed module names
Error Chain
Frequently confused with: