- lxml

- Developing with lxml

- Extending lxml

- Developing lxml

# Installing lxml

For special installation instructions regarding MS Windows and MacOS-X, see below.

Contents

- Requirements
- Installation
- Installation in ActivePython
- Building lxml from sources
- MS Windows
- MacOS-X

# Requirements

You need Python 2.3 or later.

Unless you are using a static binary distribution (e.g. a Windows binary egg from PyPI), you need to install libxml2 and libxslt, in particular:

- libxml 2.6.21 or later. It can be found here: http://xmlsoft.org/downloads.html

  If you want to use XPath, do not use libxml2 2.6.27. We recommend libxml2 2.7.2 or later.

- libxslt 1.1.15 or later. It can be found here: http://xmlsoft.org/XSLT/downloads.html

Newer versions generally contain less bugs and are therefore recommended. XML Schema support is also still worked on in libxml2, so newer versions will give you better complience with the W3C spec.

# Installation

Get the easy_install tool and run the following as super-user (or administrator):

    easy_install lxml

- On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to `easy_install` like this:

      easy_install lxml==2.2.2

- On Linux (and most other well-behaved operating systems), `easy_install` will manage to build the source distribution as long as libxml2 and libxslt are properly installed, including development packages, i.e. header files, etc. Use your package management tool to look for packages like `libxml2-dev` or `libxslt-devel` if the build fails, and make sure they are installed.

- 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 easy_install lxml

# Installation in ActivePython

ActiveState provides ready-made lxml builds for different platforms in its package repository for the PyPM package manager. PyPM is similar to apt-get in that there is a repository of automaticaly pre-built packages for Windows, Mac and Linux.

To install lxml in ActivePython, type the following on one of these operating systems:

    $ pypm install lxml

To test the installation, try:

    $ python -c "import lxml; print lxml.__file__"

This should show you the directory where the package was installed.

# Building lxml from sources

If you want to build lxml from SVN you should read how to build lxml from source (or the file `doc/build.txt` in the source tree). Building from Subversion 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.

# MS Windows

For MS Windows, the binary egg distribution of lxml is statically built against the libraries, i.e. it already includes them. There is no need to install the external libraries if you use an official lxml build from PyPI.

Unless you know what you are doing, this means: do not install libxml2 or libxslt if you use a binary build of lxml. Just use `easy_install` by following the installation instructions above.

Only if you want to upgrade the libraries and/or compile lxml from sources, you should install a binary distribution of libxml2 and libxslt. You need both libxml2 and libxslt, as well as iconv and zlib.

# MacOS-X

A macport of lxml is available. Try `port install py25-lxml`.

If you want to use a more recent lxml release, you may have to build it yourself. Apple doesn't help here, as the system libraries of libxml2 and libxslt installed under MacOS-X are horribly outdated, and updating them is everything but easy. In any case, you cannot run lxml 2.x with the system provided libraries, so you have to use newer libraries.

Luckily, lxml's `setup.py` script has built-in support for building and integrating these libraries statically during the build. Please read the MacOS-X build instructions.

A number of users also reported success with updated libraries (e.g. using fink or macports), but needed to set the runtime environment variable `DYLD_LIBRARY_PATH` to the directory where fink keeps the libraries. In any case, this method is easy to get wrong and everything but safe. Unless you know what you are doing, follow the static build instructions above.