INSTALL.txt 6.1 KB

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