INSTALL.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. Installing lxml
  2. ===============
  3. .. contents:: :depth: 1
  4. ..
  5. 1 Where to get it
  6. 2 Requirements
  7. 3 Installation
  8. 4 Building lxml from dev sources
  9. 5 Using lxml with python-libxml2
  10. 6 Source builds on MS Windows
  11. 7 Source builds on MacOS-X
  12. Where to get it
  13. ---------------
  14. lxml is generally distributed through PyPI_.
  15. .. _PyPI: http://pypi.python.org/pypi/lxml
  16. Most **Linux** platforms come with some version of lxml readily
  17. packaged, usually named ``python-lxml`` for the Python 2.x version
  18. and ``python3-lxml`` for Python 3.x. If you can use that version,
  19. the quickest way to install lxml is to use the system package
  20. manager, e.g. ``apt-get`` on Debian/Ubuntu::
  21. sudo apt-get install python3-lxml
  22. For **MacOS-X**, a `macport <http://macports.org/>`_ of lxml is available.
  23. Try something like
  24. ::
  25. sudo port install py27-lxml
  26. To install a newer version or to install lxml on other systems,
  27. see below.
  28. Requirements
  29. ------------
  30. You need Python 2.6 or later.
  31. Unless you are using a static binary distribution (e.g. from a
  32. Windows binary installer), lxml requires libxml2 and libxslt to
  33. be installed, in particular:
  34. * `libxml2 <http://xmlsoft.org/>`_ version 2.7.0 or later.
  35. * We recommend libxml2 2.9.0 or a later version.
  36. * If you want to use the feed parser interface, especially when
  37. parsing from unicode strings, do not use libxml2 2.7.4 through
  38. 2.7.6.
  39. * `libxslt <http://xmlsoft.org/XSLT/>`_ version 1.1.23 or later.
  40. * We recommend libxslt 1.1.26 or later. Version 1.1.25 will not
  41. work due to a missing library symbol.
  42. Newer versions generally contain fewer bugs and are therefore
  43. recommended. XML Schema support is also still worked on in libxml2,
  44. so newer versions will give you better compliance with the W3C spec.
  45. To install the required development packages of these dependencies
  46. on Linux systems, use your distribution specific installation tool,
  47. e.g. apt-get on Debian/Ubuntu::
  48. sudo apt-get install libxml2-dev libxslt-dev python-dev
  49. For Debian based systems, it should be enough to install the known
  50. build dependencies of the provided lxml package, e.g.
  51. ::
  52. sudo apt-get build-dep python3-lxml
  53. Installation
  54. ------------
  55. If your system does not provide binary packages or you want to install
  56. a newer version, the best way is to get the pip_ package management tool
  57. (or use a `virtualenv <https://pypi.python.org/pypi/virtualenv>`_) and
  58. run the following::
  59. pip install lxml
  60. If you are not using pip in a virtualenv and want to install lxml globally
  61. instead, you have to run the above command as admin, e.g. on Linux::
  62. sudo pip install lxml
  63. To install a specific version, either download the distribution
  64. manually and let pip install that, or pass the desired version
  65. to pip::
  66. pip install lxml==3.4.2
  67. .. _pip: http://pypi.python.org/pypi/pip
  68. To speed up the build in test environments, e.g. on a continuous
  69. integration server, disable the C compiler optimisations by setting
  70. the ``CFLAGS`` environment variable::
  71. CFLAGS="-O0" pip install lxml
  72. (The option reads "minus Oh Zero", i.e. zero optimisations.)
  73. MS Windows
  74. ..........
  75. For MS Windows, recent lxml releases feature community donated
  76. binary distributions, although you might still want to take a look
  77. at the related `FAQ entry <FAQ.html#where-are-the-binary-builds>`_.
  78. If you fail to build lxml on your MS Windows system from the signed
  79. and tested sources that we release, consider using the binary builds
  80. from PyPI or the `unofficial Windows binaries
  81. <http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml>`_
  82. that Christoph Gohlke generously provides.
  83. Linux
  84. .....
  85. On Linux (and most other well-behaved operating systems), ``pip`` will
  86. manage to build the source distribution as long as libxml2 and libxslt
  87. are properly installed, including development packages, i.e. header files,
  88. etc. See the requirements section above and use your system package
  89. management tool to look for packages like ``libxml2-dev`` or
  90. ``libxslt-devel``. If the build fails, make sure they are installed.
  91. Alternatively, setting ``STATIC_DEPS=true`` will download and build
  92. both libraries automatically in their latest version, e.g.
  93. ``STATIC_DEPS=true pip install lxml``.
  94. MacOS-X
  95. .......
  96. On MacOS-X, use the following to build the source distribution,
  97. and make sure you have a working Internet connection, as this will
  98. download libxml2 and libxslt in order to build them::
  99. STATIC_DEPS=true sudo pip install lxml
  100. Building lxml from dev sources
  101. ------------------------------
  102. If you want to build lxml from the GitHub repository, you should read
  103. `how to build lxml from source`_ (or the file ``doc/build.txt`` in the
  104. source tree). Building from developer sources or from modified
  105. distribution sources requires Cython_ to translate the lxml sources
  106. into C code. The source distribution ships with pre-generated C
  107. source files, so you do not need Cython installed to build from
  108. release sources.
  109. .. _Cython: http://www.cython.org
  110. .. _`how to build lxml from source`: build.html
  111. If you have read these instructions and still cannot manage to install lxml,
  112. you can check the archives of the `mailing list`_ to see if your problem is
  113. known or otherwise send a mail to the list.
  114. .. _`mailing list`: http://lxml.de/mailinglist/
  115. Using lxml with python-libxml2
  116. ------------------------------
  117. If you want to use lxml together with the official libxml2 Python
  118. bindings (maybe because one of your dependencies uses it), you must
  119. build lxml statically. Otherwise, the two packages will interfere in
  120. places where the libxml2 library requires global configuration, which
  121. can have any kind of effect from disappearing functionality to crashes
  122. in either of the two.
  123. To get a static build, either pass the ``--static-deps`` option to the
  124. setup.py script, or run ``pip`` with the ``STATIC_DEPS`` or
  125. ``STATICBUILD`` environment variable set to true, i.e.
  126. ::
  127. STATIC_DEPS=true pip install lxml
  128. The ``STATICBUILD`` environment variable is handled equivalently to
  129. the ``STATIC_DEPS`` variable, but is used by some other extension
  130. packages, too.
  131. Source builds on MS Windows
  132. ---------------------------
  133. Most MS Windows systems lack the necessarily tools to build software,
  134. starting with a C compiler already. Microsoft leaves it to users to
  135. install and configure them, which is usually not trivial and means
  136. that distributors cannot rely on these dependencies being available
  137. on a given system. In a way, you get what you've paid for and make
  138. others pay for it.
  139. Due to the additional lack of package management of this platform,
  140. it is best to link the library dependencies statically if you decide
  141. to build from sources, rather than using a binary installer. For
  142. that, lxml can use the `binary distribution of libxml2 and libxslt
  143. <http://www.zlatkovic.com/libxml.en.html>`_, which it downloads
  144. automatically during the static build. It needs both libxml2 and
  145. libxslt, as well as iconv and zlib, which are available from the
  146. same download site. Further build instructions are in the
  147. `source build documentation <build.html>`_.
  148. Source builds on MacOS-X
  149. ------------------------
  150. If you are not using macports or want to use a more recent lxml
  151. release, you have to build it yourself. While the pre-installed system
  152. libraries of libxml2 and libxslt are less outdated in recent MacOS-X
  153. versions than they used to be, so lxml should work them them out of the
  154. box, it is still recommended to use a static build with the most recent
  155. library versions.
  156. Luckily, lxml's ``setup.py`` script has built-in support for building
  157. and integrating these libraries statically during the build. Please
  158. read the
  159. `MacOS-X build instructions <build.html#building-lxml-on-macos-x>`_.