ImportError: lxml.html.clean module is now a separate project lxml_html_clean
Fixes the lxml 5.2 split breaking requests-html (and similar scrapers) at import. Use when the ImportError says lxml.html.clean is now the separate lxml_html_clean project. Not for plain missing lxml.
lxml 5.2 removed lxml.html.clean, and requests-html still reaches for it, so the import raises this explicit error. Install the split-out package with python -m pip install lxml_html_clean and the import works. This is the officially blessed migration path, not a hack.
The error
ImportError: lxml.html.clean module is now a separate project lxml_html_cleanFix it
- Install the split-out package
python -m pip install lxml_html_cleanExpected: Successfully installed lxml_html_clean-....
- Confirm
python -c "from requests_html import HTMLSession; print('ok')"Expected: prints ok.
- Alternative: downgrade lxml below the split
python -m pip install 'lxml<5.2'Expected: the old lxml.html.clean path exists again. Prefer step 1; old lxml forfeits security fixes.
When this applies
- the ImportError text names the lxmlhtmlclean split
- importing requests-html, facebook-scraper, or similar fails right after an lxml upgrade
- you are on lxml 5.2+
When it does NOT apply
ModuleNotFoundError: No module named 'lxml_html_clean'is the same split seen as a missing module (same install fixes it)No module named 'lxml'means lxml itself is absent
Compatibility
lxml 5.2.0+. The shim package lxmlhtmlclean tracks lxml 5.x. requests-html 0.10.0 is the version most people hit this on.
Why it happens
The lxml maintainers extracted the HTML-cleaning code into its own distribution because it was a repeated CVE source. lxml 5.2 raises this descriptive ImportError (instead of a bare ModuleNotFoundError) from a stub, precisely to tell you the new package name. Installing it restores the exact module the old code imports.
Edge cases
- If pip installs the shim but the error persists, you have two lxml installs (e.g. system and venv). The
python -m pipspelling targets the right one. - facebook-scraper and pymoviedb hit the identical error through the same lxml upgrade; the fix is the same single install.