BeautifulSoup
Python
LXML
Parsing Errors
Python Libraries

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.

Practice algorithms

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:

python
1from bs4 import BeautifulSoup
2
3html = "<html><body><p>Hello</p></body></html>"
4soup = BeautifulSoup(html, "lxml")

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.

bash
python -m pip install lxml

If you are using Python 3 explicitly:

bash
python3 -m pip install lxml

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.

bash
python -c "import lxml; print(lxml.__version__)"

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.

python
1from bs4 import BeautifulSoup
2
3html = "<html><body><p>Hello</p></body></html>"
4soup = BeautifulSoup(html, "html.parser")
5print(soup.p.text)

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:

bash
python -m pip install html5lib
python
soup = BeautifulSoup(html, "html5lib")

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:

  • 'lxml for speed and broad everyday use'
  • 'html.parser when you want zero extra dependency setup'
  • 'html5lib when 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:

python
import sys
print(sys.executable)

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 lxml in the same environment that runs your code.
  • 'python -m pip install lxml is safer than relying on plain pip.'
  • If lxml is not required, you can use html.parser or html5lib instead.
  • Virtual-environment and interpreter mismatches are the most common hidden cause.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
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.

Practice algorithms