Blame INSTALL.txt

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