ImportError: cannot import name 'Document' from partially initialized module 'readability'
Fixes the readability circular-import failure caused by your own readability.py. Use when the ImportError says `partially initialized module 'readability'`. Not for the wrong-package variant (no 'partially initialized' in the message).
A file named readability.py in your working directory is shadowing the library, and Python is importing your half-initialized file instead of the package. Rename your file (and delete __pycache__), and from readability import Document works.
The error
ImportError: cannot import name 'Document' from partially initialized module 'readability'Fix it
- Confirm the shadowing
python -c "import readability; print(readability.__file__)"Expected: a project path ending in readability.py means your file is the problem.
- Rename your file
Rename readability.py to something like extract_article.py, clear __pycache__, then:
python -c "from readability import Document; print('ok')"Expected: prints ok.
When this applies
- the message contains
partially initialized module 'readability' - your script sits next to a file called
readability.py
When it does NOT apply
- without
partially initialized, it is the wrong-PyPI-package variant No module named 'readability'is the missing install
Compatibility
All readability-lxml versions. The partially initialized phrasing is Python 3's circular-import diagnostic.
Why it happens
When your script is readability.py and it runs from readability import Document, Python starts initializing YOUR file as the readability module, then the from-import asks that same half-initialized module for Document, which does not exist yet. Python detects the cycle and reports partially initialized module. The script's directory beating site-packages is what starts the cycle.
Edge cases
- The traceback often shows your own filename twice. That doubling is the signature of this trap.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.