How to Install lxml in Python

v6.0.3 General Purpose Python >=3.8 BSD-3-Clause

Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.

Install pip install lxml

What is lxml?

Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.

lxml is a Pythonic, mature binding for the libxml2 and libxslt libraries. It provides safe and convenient access to these libraries using the ElementTree API.

It extends the ElementTree API significantly to offer support for XPath, RelaxNG, XML Schema, XSLT, C14N and much more.

To contact the project, go to the or see our bug tracker at

Quick Start

Minimal example to get started with lxml:

import lxml

print(lxml.__version__)

Installation

pip (standard)

pip install lxml

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install lxml

pip3

pip3 install lxml

conda

conda install -c conda-forge lxml

Poetry

poetry add lxml

Verify the Installation

After installing, confirm the package is available:

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

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing lxml with pip.

ModuleNotFoundError: No module named 'lxml'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install lxml. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'lxml' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install lxml to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'lxml'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show lxml and upgrade with pip install --upgrade lxml.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install lxml. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user lxml

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org lxml

Recent Releases

VersionReleased
6.0.3 latest 2026-04-09
6.0.2 2025-09-22
6.0.1 2025-08-22
6.0.0 2025-06-26
5.4.0 2025-04-23

Full release history on PyPI →

Manage lxml

Upgrade to latest version

pip install --upgrade lxml

Install a specific version

pip install lxml==6.0.3

Uninstall

pip uninstall lxml

Check what is installed

pip show lxml

Last updated: 2026-04-11 • Data from PyPI