• November 9, 2024

Pip Install Lxml

Installing lxml

Installing lxml

Contents
Where to get it
Requirements
Installation
Building lxml from dev sources
Using lxml with python-libxml2
Source builds on MS Windows
Source builds on MacOS-X
lxml is generally distributed through PyPI.
Most Linux platforms come with some version of lxml readily
packaged, usually named python-lxml for the Python 2. x version
and python3-lxml for Python 3. x. If you can use that version,
the quickest way to install lxml is to use the system package
manager, e. g. apt-get on Debian/Ubuntu:
sudo apt-get install python3-lxml
For MacOS-X, a macport of lxml is available.
Try something like
sudo port install py27-lxml
To install a newer version or to install lxml on other systems,
see below.
You need Python 2. 7 or 3. 4+.
Unless you are using a static binary distribution (e. from a
Windows binary installer), lxml requires libxml2 and libxslt to
be installed, in particular:
libxml2 version 2. 9. 2 or later.
libxslt version 1. 1. 27 or later.
We recommend libxslt 1. 28 or later.
Newer versions generally contain fewer bugs and are therefore
recommended. XML Schema support is also still worked on in libxml2,
so newer versions will give you better compliance with the W3C spec.
To install the required development packages of these dependencies
on Linux systems, use your distribution specific installation tool,
e. apt-get on Debian/Ubuntu:
sudo apt-get install libxml2-dev libxslt-dev python-dev
For Debian based systems, it should be enough to install the known
build dependencies of the provided lxml package, e. g.
sudo apt-get build-dep python3-lxml
If your system does not provide binary packages or you want to install
a newer version, the best way is to get the pip package management tool
(or use a virtualenv) and
run the following:
pip install lxml
If you are not using pip in a virtualenv and want to install lxml globally
instead, you have to run the above command as admin, e. on Linux:
sudo pip install lxml
To install a specific version, either download the distribution
manually and let pip install that, or pass the desired version
to pip:
pip install lxml==3. 4. 2
To speed up the build in test environments, e. on a continuous
integration server, disable the C compiler optimisations by setting
the CFLAGS environment variable:
CFLAGS=”-O0″ pip install lxml
(The option reads “minus Oh Zero”, i. e. zero optimisations. )
MS Windows
For MS Windows, recent lxml releases feature community donated
binary distributions, although you might still want to take a look
at the related FAQ entry.
If you fail to build lxml on your MS Windows system from the signed
and tested sources that we release, consider using the binary builds
from PyPI or the unofficial Windows binaries
that Christoph Gohlke generously provides.
Linux
On Linux (and most other well-behaved operating systems), pip will
manage to build the source distribution as long as libxml2 and libxslt
are properly installed, including development packages, i. header files,
etc. See the requirements section above and use your system package
management tool to look for packages like libxml2-dev or
libxslt-devel. If the build fails, make sure they are installed.
Alternatively, setting STATIC_DEPS=true will download and build
both libraries automatically in their latest version, e. g.
STATIC_DEPS=true pip install lxml.
MacOS-X
On MacOS-X, use the following to build the source distribution,
and make sure you have a working Internet connection, as this will
download libxml2 and libxslt in order to build them:
STATIC_DEPS=true sudo pip install lxml
If you want to build lxml from the GitHub repository, you should read
how to build lxml from source (or the file doc/ in the
source tree). Building from developer sources or from modified
distribution sources requires Cython to translate the lxml sources
into C code. The source distribution ships with pre-generated C
source files, so you do not need Cython installed to build from
release sources.
If you have read these instructions and still cannot manage to install lxml,
you can check the archives of the mailing list to see if your problem is
known or otherwise send a mail to the list.
If you want to use lxml together with the official libxml2 Python
bindings (maybe because one of your dependencies uses it), you must
build lxml statically. Otherwise, the two packages will interfere in
places where the libxml2 library requires global configuration, which
can have any kind of effect from disappearing functionality to crashes
in either of the two.
To get a static build, either pass the –static-deps option to the
script, or run pip with the STATIC_DEPS or
STATICBUILD environment variable set to true, i. e.
STATIC_DEPS=true pip install lxml
The STATICBUILD environment variable is handled equivalently to
the STATIC_DEPS variable, but is used by some other extension
packages, too.
Most MS Windows systems lack the necessarily tools to build software,
starting with a C compiler already. Microsoft leaves it to users to
install and configure them, which is usually not trivial and means
that distributors cannot rely on these dependencies being available
on a given system. In a way, you get what you’ve paid for and make
others pay for it.
Due to the additional lack of package management of this platform,
it is best to link the library dependencies statically if you decide
to build from sources, rather than using a binary installer. For
that, lxml can use the binary distribution of libxml2 and libxslt, which it downloads
automatically during the static build. It needs both libxml2 and
libxslt, as well as iconv and zlib, which are available from the
same download site. Further build instructions are in the
source build documentation.
If you are not using macports or want to use a more recent lxml
release, you have to build it yourself. While the pre-installed system
libraries of libxml2 and libxslt are less outdated in recent MacOS-X
versions than they used to be, so lxml should work with them out of the
box, it is still recommended to use a static build with the most recent
library versions.
Luckily, lxml’s script has built-in support for building
and integrating these libraries statically during the build. Please
read the
MacOS-X build instructions.
lxml - PyPI

lxml – PyPI

Project description
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 project home page or see our bug tracker at
In case you want to use the current in-development version of lxml,
you can get it from the github repository at. Note that this requires Cython to
build the sources, see the build instructions on the project home
page. To the same end, running easy_install lxml==dev will
install lxml from
if you have
an appropriate version of Cython installed.
After an official release of a new stable series, bug fixes may become
available at.
Running easy_install lxml==4. 6bugfix will install
the unreleased branch state from
as soon as a maintenance branch has been established. Note that this
requires Cython to be installed at an appropriate version for the build.
4. 6. 3 (2021-03-21)
Bugs fixed
A vulnerability (CVE-2021-28957) was discovered in the HTML Cleaner by Kevin Chung,
which allowed JavaScript to pass through. The cleaner now removes the HTML5
formaction attribute.
Download files
Download the file for your platform. If you’re not sure which to choose, learn more about installing packages.
Files for lxml, version 4. 3
Filename, size
File type
Python version
Upload date
Hashes
(4. 5 MB)
Wheel
cp27
Mar 21, 2021
View
(5. 3 MB)
(5. 5 MB)
(3. 2 MB)
(3. 5 MB)
(7. 0 MB)
cp310
Aug 12, 2021
(6. 9 MB)
cp35
Mar 24, 2021
(6. 4 MB)
May 2, 2021
(6. 3 MB)
cp36
(5. 4 MB)
(6. 5 MB)
(6. 7 MB)
cp37
(4. 6 MB)
cp38
(7. 3 MB)
(6. 8 MB)
cp39
(7. 4 MB)
Source
None
Mar 22, 2021
View
Installing lxml

Installing lxml

Contents
Where to get it
Requirements
Installation
Building lxml from dev sources
Using lxml with python-libxml2
Source builds on MS Windows
Source builds on MacOS-X
lxml is generally distributed through PyPI.
Most Linux platforms come with some version of lxml readily
packaged, usually named python-lxml for the Python 2. x version
and python3-lxml for Python 3. x. If you can use that version,
the quickest way to install lxml is to use the system package
manager, e. g. apt-get on Debian/Ubuntu:
sudo apt-get install python3-lxml
For MacOS-X, a macport of lxml is available.
Try something like
sudo port install py27-lxml
To install a newer version or to install lxml on other systems,
see below.
You need Python 2. 7 or 3. 4+.
Unless you are using a static binary distribution (e. from a
Windows binary installer), lxml requires libxml2 and libxslt to
be installed, in particular:
libxml2 version 2. 9. 2 or later.
libxslt version 1. 1. 27 or later.
We recommend libxslt 1. 28 or later.
Newer versions generally contain fewer bugs and are therefore
recommended. XML Schema support is also still worked on in libxml2,
so newer versions will give you better compliance with the W3C spec.
To install the required development packages of these dependencies
on Linux systems, use your distribution specific installation tool,
e. apt-get on Debian/Ubuntu:
sudo apt-get install libxml2-dev libxslt-dev python-dev
For Debian based systems, it should be enough to install the known
build dependencies of the provided lxml package, e. g.
sudo apt-get build-dep python3-lxml
If your system does not provide binary packages or you want to install
a newer version, the best way is to get the pip package management tool
(or use a virtualenv) and
run the following:
pip install lxml
If you are not using pip in a virtualenv and want to install lxml globally
instead, you have to run the above command as admin, e. on Linux:
sudo pip install lxml
To install a specific version, either download the distribution
manually and let pip install that, or pass the desired version
to pip:
pip install lxml==3. 4. 2
To speed up the build in test environments, e. on a continuous
integration server, disable the C compiler optimisations by setting
the CFLAGS environment variable:
CFLAGS=”-O0″ pip install lxml
(The option reads “minus Oh Zero”, i. e. zero optimisations. )
MS Windows
For MS Windows, recent lxml releases feature community donated
binary distributions, although you might still want to take a look
at the related FAQ entry.
If you fail to build lxml on your MS Windows system from the signed
and tested sources that we release, consider using the binary builds
from PyPI or the unofficial Windows binaries
that Christoph Gohlke generously provides.
Linux
On Linux (and most other well-behaved operating systems), pip will
manage to build the source distribution as long as libxml2 and libxslt
are properly installed, including development packages, i. header files,
etc. See the requirements section above and use your system package
management tool to look for packages like libxml2-dev or
libxslt-devel. If the build fails, make sure they are installed.
Alternatively, setting STATIC_DEPS=true will download and build
both libraries automatically in their latest version, e. g.
STATIC_DEPS=true pip install lxml.
MacOS-X
On MacOS-X, use the following to build the source distribution,
and make sure you have a working Internet connection, as this will
download libxml2 and libxslt in order to build them:
STATIC_DEPS=true sudo pip install lxml
If you want to build lxml from the GitHub repository, you should read
how to build lxml from source (or the file doc/ in the
source tree). Building from developer sources or from modified
distribution sources requires Cython to translate the lxml sources
into C code. The source distribution ships with pre-generated C
source files, so you do not need Cython installed to build from
release sources.
If you have read these instructions and still cannot manage to install lxml,
you can check the archives of the mailing list to see if your problem is
known or otherwise send a mail to the list.
If you want to use lxml together with the official libxml2 Python
bindings (maybe because one of your dependencies uses it), you must
build lxml statically. Otherwise, the two packages will interfere in
places where the libxml2 library requires global configuration, which
can have any kind of effect from disappearing functionality to crashes
in either of the two.
To get a static build, either pass the –static-deps option to the
script, or run pip with the STATIC_DEPS or
STATICBUILD environment variable set to true, i. e.
STATIC_DEPS=true pip install lxml
The STATICBUILD environment variable is handled equivalently to
the STATIC_DEPS variable, but is used by some other extension
packages, too.
Most MS Windows systems lack the necessarily tools to build software,
starting with a C compiler already. Microsoft leaves it to users to
install and configure them, which is usually not trivial and means
that distributors cannot rely on these dependencies being available
on a given system. In a way, you get what you’ve paid for and make
others pay for it.
Due to the additional lack of package management of this platform,
it is best to link the library dependencies statically if you decide
to build from sources, rather than using a binary installer. For
that, lxml can use the binary distribution of libxml2 and libxslt, which it downloads
automatically during the static build. It needs both libxml2 and
libxslt, as well as iconv and zlib, which are available from the
same download site. Further build instructions are in the
source build documentation.
If you are not using macports or want to use a more recent lxml
release, you have to build it yourself. While the pre-installed system
libraries of libxml2 and libxslt are less outdated in recent MacOS-X
versions than they used to be, so lxml should work with them out of the
box, it is still recommended to use a static build with the most recent
library versions.
Luckily, lxml’s script has built-in support for building
and integrating these libraries statically during the build. Please
read the
MacOS-X build instructions.

Frequently Asked Questions about pip install lxml

What is PIP install lxml?

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.

How do I get lxml?

Where to get it. lxml is generally distributed through PyPI. … Requirements. You need Python 2.7 or 3.4+. … Installation. … Building lxml from dev sources. … Using lxml with python-libxml2. … Source builds on MS Windows. … Source builds on MacOS-X.

How do I install lxml on Windows 10?

Install LXMLDownload LXML 3.4.4 from HERE for your version of Windows and PC architecture.Run the EXE file.Apr 4, 2015

Leave a Reply

Your email address will not be published. Required fields are marked *