bs4.FeatureNotFound Couldn't find a tree builder with the features you requested lxml. Do you need to install a parser library?
Data Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.
Introduction
This Beautiful Soup error means the parser you asked for is not available in the Python environment that is currently running your code. Most often, the code requested lxml, but the lxml package is not installed in that environment, or the interpreter and package manager are pointing at different virtual environments.
Why Beautiful Soup Raises FeatureNotFound
Beautiful Soup is not itself an HTML parser. It is a wrapper that can use different parser backends such as:
- Python's built-in
html.parser - '
lxml' - '
html5lib'
When you write code like this:
Beautiful Soup tries to load the lxml tree builder. If lxml is unavailable, you get:
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml
So the problem is usually not your HTML. It is the parser dependency.
Install the Missing Parser in the Right Environment
The usual fix is to install lxml where the script is actually running.
If you are using Python 3 explicitly:
Using python -m pip is safer than typing plain pip because it ties the installation to a specific interpreter. That avoids a common virtual-environment mismatch where pip installs into one environment and your script runs in another.
Confirm Which Interpreter Is Running
If you think lxml is already installed, verify that the executing interpreter can import it.
If that fails, the package is not available to that interpreter, even if some other environment on your machine has it installed.
This is a common cause of confusion in:
- virtual environments
- Jupyter notebooks
- IDE-managed Python interpreters
- Docker containers
Use Another Parser if lxml Is Not Required
If you do not specifically need lxml, you can switch to a parser that is available.
This often works fine for simpler scraping tasks because html.parser ships with Python.
You can also use html5lib if you need a more forgiving HTML5-style parser:
The important point is that the parser string in your code must match a parser library that is actually installed.
Choosing Between Parsers
A practical rule of thumb is:
- '
lxmlfor speed and broad everyday use' - '
html.parserwhen you want zero extra dependency setup' - '
html5libwhen you need very forgiving parsing of messy HTML'
There is no single parser that is "always correct." The best choice depends on installation constraints, performance needs, and how broken the input HTML tends to be.
Jupyter and IDE Cases
This error frequently appears when a package was installed in the terminal but the notebook kernel or IDE is using another interpreter.
A quick check inside Python can help:
That tells you which interpreter is running. Install the parser into that environment, not into whichever one you happened to use in a shell earlier.
Common Pitfalls
The biggest mistake is installing lxml with one Python interpreter and running the script with another. That makes it look like the installation failed when the real issue is environment mismatch.
Another mistake is hardcoding "lxml" even when the project does not require it. If portability matters, html.parser may be a better baseline.
People also forget that Beautiful Soup itself is separate from parser packages. Installing beautifulsoup4 does not automatically guarantee that lxml or html5lib is present.
Finally, do not assume every parser behaves identically on malformed HTML. Switching parsers may change the parse tree as well as fix the import problem.
Summary
- This error means Beautiful Soup could not load the parser backend you requested.
- The usual fix is installing
lxmlin the same environment that runs your code. - '
python -m pip install lxmlis safer than relying on plainpip.' - If
lxmlis not required, you can usehtml.parserorhtml5libinstead. - Virtual-environment and interpreter mismatches are the most common hidden cause.
Related reading
- BufferError Local Queue full in Python
- Build an approximately uniform grid from random sample python
- Building a minimal plugin architecture in Python
- Building an SVM with Tensorflow
- Building Kivy Android app with Tensorflow
- Building Tensorflow Graphs Inside of Functions
- built-in max heap API in Python
- builtins.TypeError must be str, not bytes
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.