bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5lib
Fixes BeautifulSoup raising FeatureNotFound when you ask for the html5lib tree builder and it is not installed. Use when the traceback names the html5lib feature set. Not for the lxml variant (same shape, different package).
You asked BeautifulSoup for the html5lib parser (BeautifulSoup(html, 'html5lib')) without having html5lib installed. Run pip install html5lib and the same line works. If you cannot install it, switch to 'html.parser', which ships with Python.
The error
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html5libFix it
- Install html5lib
python -m pip install html5libExpected: Successfully installed html5lib-1.1.
- Re-run your parse line unchanged
python -c "from bs4 import BeautifulSoup; print(BeautifulSoup('hi', 'html5lib').get_text())"Expected: prints hi.
- Alternative without new installs
soup = BeautifulSoup(html, 'html.parser')Expected: parses with the stdlib parser. Behavior differs slightly on broken markup, which is the whole reason people pick html5lib.
When this applies
- the FeatureNotFound message names
html5lib - you passed
'html5lib'as the parser, or a library did on your behalf
When it does NOT apply
- FeatureNotFound naming
lxmlmeans install lxml instead No module named 'html5lib'from a direct import is the same missing package without bs4 in the middle
Compatibility
All bs4 4.x with html5lib 1.1. html5lib is the most lenient parser bs4 supports, which is why guides recommend it.
Why it happens
BeautifulSoup is a tree API over pluggable parsers. Naming 'html5lib' selects that parser, and if it is not installed bs4 raises FeatureNotFound instead of guessing. The message names the missing feature set, so the fix is mechanical.
Edge cases
- html5lib is slower than lxml. Pick it for leniency on broken markup, not for speed.
- If html5lib IS installed but the error persists, it is the two-interpreter problem.
python -m pip install html5libtargets the right one.
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.