ModuleNotFoundError: No module named 'html5lib'
Fixes the plain missing-module error for html5lib. Use when `import html5lib` fails with ModuleNotFoundError naming html5lib, often surfacing through a dependency like xhtml2pdf or BeautifulSoup. Not for the webencodings gap underneath it.
html5lib is not installed in the running Python. Run python -m pip install html5lib. It usually arrives as a dependency of something else (xhtml2pdf, bs4 with the html5lib parser), so its absence means the dependency set was disturbed.
The error
ModuleNotFoundError: No module named 'html5lib'Fix it
- Install html5lib
python -m pip install html5libExpected: Successfully installed html5lib-1.1 with webencodings and six.
- Confirm
python -c "import html5lib; print('ok')"Expected: prints ok.
When this applies
import html5libfails naming the module- a dependency (xhtml2pdf, weasyprint-era stacks, bs4) fails importing it
- a
--no-depsinstall dropped it
When it does NOT apply
No module named 'webencodings'means html5lib IS there but its own dependency is missingFeatureNotFound ... html5libfrom bs4 is the same missing package seen one layer up
Compatibility
html5lib 1.1 current. Pure Python, no compiler needed.
Why it happens
html5lib is almost always a transitive dependency, so nobody installs it on purpose and nobody notices when it goes missing until an import chain touches it. --no-deps installs and hand-pruned requirements are the usual way it gets dropped.
Edge cases
- If you only need an HTML parser for bs4,
html.parser(stdlib) avoids the dependency entirely. Install html5lib when something specifically asks for it.