INSTALL.txt 7.3 KB

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