Imported Upstream version 2.3.5
[platform/upstream/python-lxml.git] / doc / html / build.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <meta name="generator" content="Docutils 0.8.1: http://docutils.sourceforge.net/" />
6 <title>How to build lxml from source</title>
7 <link rel="stylesheet" href="style.css" type="text/css" />
8 </head>
9 <body>
10 <div class="document" id="how-to-build-lxml-from-source">
11 <div class="sidemenu"><ul id="lxml-section"><li><span class="section title">lxml</span><ul class="menu foreign" id="index-menu"><li class="menu title"><a href="index.html">lxml</a><ul class="submenu"><li class="menu item"><a href="index.html#introduction">Introduction</a></li><li class="menu item"><a href="index.html#support-the-project">Support the project</a></li><li class="menu item"><a href="index.html#documentation">Documentation</a></li><li class="menu item"><a href="index.html#download">Download</a></li><li class="menu item"><a href="index.html#mailing-list">Mailing list</a></li><li class="menu item"><a href="index.html#bug-tracker">Bug tracker</a></li><li class="menu item"><a href="index.html#license">License</a></li><li class="menu item"><a href="index.html#old-versions">Old Versions</a></li><li class="menu item"><a href="index.html#legal-notice-for-donations">Legal Notice for Donations</a></li></ul></li></ul><ul class="menu foreign" id="intro-menu"><li class="menu title"><a href="intro.html">Why lxml?</a><ul class="submenu"><li class="menu item"><a href="intro.html#motto">Motto</a></li><li class="menu item"><a href="intro.html#aims">Aims</a></li></ul></li></ul><ul class="menu foreign" id="installation-menu"><li class="menu title"><a href="installation.html">Installing lxml</a><ul class="submenu"><li class="menu item"><a href="installation.html#requirements">Requirements</a></li><li class="menu item"><a href="installation.html#installation">Installation</a></li><li class="menu item"><a href="installation.html#building-lxml-from-sources">Building lxml from sources</a></li><li class="menu item"><a href="installation.html#using-lxml-with-python-libxml2">Using lxml with python-libxml2</a></li><li class="menu item"><a href="installation.html#ms-windows">MS Windows</a></li><li class="menu item"><a href="installation.html#macos-x">MacOS-X</a></li></ul></li></ul><ul class="menu foreign" id="performance-menu"><li class="menu title"><a href="performance.html">Benchmarks and Speed</a><ul class="submenu"><li class="menu item"><a href="performance.html#general-notes">General notes</a></li><li class="menu item"><a href="performance.html#how-to-read-the-timings">How to read the timings</a></li><li class="menu item"><a href="performance.html#parsing-and-serialising">Parsing and Serialising</a></li><li class="menu item"><a href="performance.html#the-elementtree-api">The ElementTree API</a></li><li class="menu item"><a href="performance.html#xpath">XPath</a></li><li class="menu item"><a href="performance.html#a-longer-example">A longer example</a></li><li class="menu item"><a href="performance.html#lxml-objectify">lxml.objectify</a></li></ul></li></ul><ul class="menu foreign" id="compatibility-menu"><li class="menu title"><a href="compatibility.html">ElementTree compatibility of lxml.etree</a></li></ul><ul class="menu foreign" id="FAQ-menu"><li class="menu title"><a href="FAQ.html">lxml FAQ - Frequently Asked Questions</a><ul class="submenu"><li class="menu item"><a href="FAQ.html#general-questions">General Questions</a></li><li class="menu item"><a href="FAQ.html#installation">Installation</a></li><li class="menu item"><a href="FAQ.html#contributing">Contributing</a></li><li class="menu item"><a href="FAQ.html#bugs">Bugs</a></li><li class="menu item"><a href="FAQ.html#id1">Threading</a></li><li class="menu item"><a href="FAQ.html#parsing-and-serialisation">Parsing and Serialisation</a></li><li class="menu item"><a href="FAQ.html#xpath-and-document-traversal">XPath and Document Traversal</a></li></ul></li></ul></li></ul><ul id="Developing with lxml-section"><li><span class="section title">Developing with lxml</span><ul class="menu foreign" id="tutorial-menu"><li class="menu title"><a href="tutorial.html">The lxml.etree Tutorial</a><ul class="submenu"><li class="menu item"><a href="tutorial.html#the-element-class">The Element class</a></li><li class="menu item"><a href="tutorial.html#the-elementtree-class">The ElementTree class</a></li><li class="menu item"><a href="tutorial.html#parsing-from-strings-and-files">Parsing from strings and files</a></li><li class="menu item"><a href="tutorial.html#namespaces">Namespaces</a></li><li class="menu item"><a href="tutorial.html#the-e-factory">The E-factory</a></li><li class="menu item"><a href="tutorial.html#elementpath">ElementPath</a></li></ul></li></ul><ul class="menu foreign" id="api index-menu"><li class="menu title"><a href="api/index.html">API reference</a></li></ul><ul class="menu foreign" id="api-menu"><li class="menu title"><a href="api.html">APIs specific to lxml.etree</a><ul class="submenu"><li class="menu item"><a href="api.html#lxml-etree">lxml.etree</a></li><li class="menu item"><a href="api.html#other-element-apis">Other Element APIs</a></li><li class="menu item"><a href="api.html#trees-and-documents">Trees and Documents</a></li><li class="menu item"><a href="api.html#iteration">Iteration</a></li><li class="menu item"><a href="api.html#error-handling-on-exceptions">Error handling on exceptions</a></li><li class="menu item"><a href="api.html#error-logging">Error logging</a></li><li class="menu item"><a href="api.html#serialisation">Serialisation</a></li><li class="menu item"><a href="api.html#cdata">CDATA</a></li><li class="menu item"><a href="api.html#xinclude-and-elementinclude">XInclude and ElementInclude</a></li><li class="menu item"><a href="api.html#write-c14n-on-elementtree">write_c14n on ElementTree</a></li></ul></li></ul><ul class="menu foreign" id="parsing-menu"><li class="menu title"><a href="parsing.html">Parsing XML and HTML with lxml</a><ul class="submenu"><li class="menu item"><a href="parsing.html#parsers">Parsers</a></li><li class="menu item"><a href="parsing.html#the-target-parser-interface">The target parser interface</a></li><li class="menu item"><a href="parsing.html#the-feed-parser-interface">The feed parser interface</a></li><li class="menu item"><a href="parsing.html#iterparse-and-iterwalk">iterparse and iterwalk</a></li><li class="menu item"><a href="parsing.html#python-unicode-strings">Python unicode strings</a></li></ul></li></ul><ul class="menu foreign" id="validation-menu"><li class="menu title"><a href="validation.html">Validation with lxml</a><ul class="submenu"><li class="menu item"><a href="validation.html#validation-at-parse-time">Validation at parse time</a></li><li class="menu item"><a href="validation.html#id1">DTD</a></li><li class="menu item"><a href="validation.html#relaxng">RelaxNG</a></li><li class="menu item"><a href="validation.html#xmlschema">XMLSchema</a></li><li class="menu item"><a href="validation.html#id2">Schematron</a></li><li class="menu item"><a href="validation.html#id3">(Pre-ISO-Schematron)</a></li></ul></li></ul><ul class="menu foreign" id="xpathxslt-menu"><li class="menu title"><a href="xpathxslt.html">XPath and XSLT with lxml</a><ul class="submenu"><li class="menu item"><a href="xpathxslt.html#xpath">XPath</a></li><li class="menu item"><a href="xpathxslt.html#xslt">XSLT</a></li></ul></li></ul><ul class="menu foreign" id="objectify-menu"><li class="menu title"><a href="objectify.html">lxml.objectify</a><ul class="submenu"><li class="menu item"><a href="objectify.html#the-lxml-objectify-api">The lxml.objectify API</a></li><li class="menu item"><a href="objectify.html#asserting-a-schema">Asserting a Schema</a></li><li class="menu item"><a href="objectify.html#objectpath">ObjectPath</a></li><li class="menu item"><a href="objectify.html#python-data-types">Python data types</a></li><li class="menu item"><a href="objectify.html#how-data-types-are-matched">How data types are matched</a></li><li class="menu item"><a href="objectify.html#what-is-different-from-lxml-etree">What is different from lxml.etree?</a></li></ul></li></ul><ul class="menu foreign" id="lxmlhtml-menu"><li class="menu title"><a href="lxmlhtml.html">lxml.html</a><ul class="submenu"><li class="menu item"><a href="lxmlhtml.html#parsing-html">Parsing HTML</a></li><li class="menu item"><a href="lxmlhtml.html#html-element-methods">HTML Element Methods</a></li><li class="menu item"><a href="lxmlhtml.html#running-html-doctests">Running HTML doctests</a></li><li class="menu item"><a href="lxmlhtml.html#creating-html-with-the-e-factory">Creating HTML with the E-factory</a></li><li class="menu item"><a href="lxmlhtml.html#working-with-links">Working with links</a></li><li class="menu item"><a href="lxmlhtml.html#forms">Forms</a></li><li class="menu item"><a href="lxmlhtml.html#cleaning-up-html">Cleaning up HTML</a></li><li class="menu item"><a href="lxmlhtml.html#html-diff">HTML Diff</a></li><li class="menu item"><a href="lxmlhtml.html#examples">Examples</a></li></ul></li></ul><ul class="menu foreign" id="cssselect-menu"><li class="menu title"><a href="cssselect.html">lxml.cssselect</a><ul class="submenu"><li class="menu item"><a href="cssselect.html#the-cssselector-class">The CSSSelector class</a></li><li class="menu item"><a href="cssselect.html#css-selectors">CSS Selectors</a></li><li class="menu item"><a href="cssselect.html#namespaces">Namespaces</a></li><li class="menu item"><a href="cssselect.html#limitations">Limitations</a></li></ul></li></ul><ul class="menu foreign" id="elementsoup-menu"><li class="menu title"><a href="elementsoup.html">BeautifulSoup Parser</a><ul class="submenu"><li class="menu item"><a href="elementsoup.html#parsing-with-the-soupparser">Parsing with the soupparser</a></li><li class="menu item"><a href="elementsoup.html#entity-handling">Entity handling</a></li><li class="menu item"><a href="elementsoup.html#using-soupparser-as-a-fallback">Using soupparser as a fallback</a></li><li class="menu item"><a href="elementsoup.html#using-only-the-encoding-detection">Using only the encoding detection</a></li></ul></li></ul><ul class="menu foreign" id="html5parser-menu"><li class="menu title"><a href="html5parser.html">html5lib Parser</a><ul class="submenu"><li class="menu item"><a href="html5parser.html#differences-to-regular-html-parsing">Differences to regular HTML parsing</a></li><li class="menu item"><a href="html5parser.html#function-reference">Function Reference</a></li></ul></li></ul></li></ul><ul id="Extending lxml-section"><li><span class="section title">Extending lxml</span><ul class="menu foreign" id="resolvers-menu"><li class="menu title"><a href="resolvers.html">Document loading and URL resolving</a><ul class="submenu"><li class="menu item"><a href="resolvers.html#xml-catalogs">XML Catalogs</a></li><li class="menu item"><a href="resolvers.html#uri-resolvers">URI Resolvers</a></li><li class="menu item"><a href="resolvers.html#document-loading-in-context">Document loading in context</a></li><li class="menu item"><a href="resolvers.html#i-o-access-control-in-xslt">I/O access control in XSLT</a></li></ul></li></ul><ul class="menu foreign" id="extensions-menu"><li class="menu title"><a href="extensions.html">Python extensions for XPath and XSLT</a><ul class="submenu"><li class="menu item"><a href="extensions.html#xpath-extension-functions">XPath Extension functions</a></li><li class="menu item"><a href="extensions.html#xslt-extension-elements">XSLT extension elements</a></li></ul></li></ul><ul class="menu foreign" id="element classes-menu"><li class="menu title"><a href="element_classes.html">Using custom Element classes in lxml</a><ul class="submenu"><li class="menu item"><a href="element_classes.html#background-on-element-proxies">Background on Element proxies</a></li><li class="menu item"><a href="element_classes.html#element-initialization">Element initialization</a></li><li class="menu item"><a href="element_classes.html#setting-up-a-class-lookup-scheme">Setting up a class lookup scheme</a></li><li class="menu item"><a href="element_classes.html#generating-xml-with-custom-classes">Generating XML with custom classes</a></li><li class="menu item"><a href="element_classes.html#id1">Implementing namespaces</a></li></ul></li></ul><ul class="menu foreign" id="sax-menu"><li class="menu title"><a href="sax.html">Sax support</a><ul class="submenu"><li class="menu item"><a href="sax.html#building-a-tree-from-sax-events">Building a tree from SAX events</a></li><li class="menu item"><a href="sax.html#producing-sax-events-from-an-elementtree-or-element">Producing SAX events from an ElementTree or Element</a></li><li class="menu item"><a href="sax.html#interfacing-with-pulldom-minidom">Interfacing with pulldom/minidom</a></li></ul></li></ul><ul class="menu foreign" id="capi-menu"><li class="menu title"><a href="capi.html">The public C-API of lxml.etree</a><ul class="submenu"><li class="menu item"><a href="capi.html#writing-external-modules-in-cython">Writing external modules in Cython</a></li><li class="menu item"><a href="capi.html#writing-external-modules-in-c">Writing external modules in C</a></li></ul></li></ul></li></ul><ul id="Developing lxml-section"><li><span class="section title">Developing lxml</span><ul class="menu current" id="build-menu"><li class="menu title"><a href="build.html">How to build lxml from source</a><ul class="submenu"><li class="menu item"><a href="build.html#cython">Cython</a></li><li class="menu item"><a href="build.html#github-git-and-hg">Github, git and hg</a></li><li class="menu item"><a href="build.html#id2">Setuptools</a></li><li class="menu item"><a href="build.html#running-the-tests-and-reporting-errors">Running the tests and reporting errors</a></li><li class="menu item"><a href="build.html#building-an-egg">Building an egg</a></li><li class="menu item"><a href="build.html#building-lxml-on-macos-x">Building lxml on MacOS-X</a></li><li class="menu item"><a href="build.html#static-linking-on-windows">Static linking on Windows</a></li><li class="menu item"><a href="build.html#building-debian-packages-from-svn-sources">Building Debian packages from SVN sources</a></li></ul></li></ul><ul class="menu foreign" id="lxml source howto-menu"><li class="menu title"><a href="lxml-source-howto.html">How to read the source of lxml</a><ul class="submenu"><li class="menu item"><a href="lxml-source-howto.html#what-is-cython">What is Cython?</a></li><li class="menu item"><a href="lxml-source-howto.html#where-to-start">Where to start?</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-etree">lxml.etree</a></li><li class="menu item"><a href="lxml-source-howto.html#python-modules">Python modules</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-objectify">lxml.objectify</a></li><li class="menu item"><a href="lxml-source-howto.html#lxml-html">lxml.html</a></li></ul></li></ul><ul class="menu foreign" id="changes 2 3 5-menu"><li class="menu title"><a href="changes-2.3.5.html">Release Changelog</a></li></ul><ul class="menu foreign" id="credits-menu"><li class="menu title"><a href="credits.html">Credits</a><ul class="submenu"><li class="menu item"><a href="credits.html#main-contributors">Main contributors</a></li><li class="menu item"><a href="credits.html#special-thanks-goes-to">Special thanks goes to:</a></li></ul></li></ul></li><li><a href="http://lxml.de/sitemap.html">Sitemap</a></li></ul></div><h1 class="title">How to build lxml from source</h1>
12
13 <p>To build lxml from source, you need libxml2 and libxslt properly
14 installed, <em>including the header files</em>.  These are likely shipped in
15 separate <tt class="docutils literal"><span class="pre">-dev</span></tt> or <tt class="docutils literal"><span class="pre">-devel</span></tt> packages like <tt class="docutils literal"><span class="pre">libxml2-dev</span></tt>, which
16 you must install before trying to build lxml.  The build process also
17 requires <a class="reference external" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a>.  The lxml source distribution comes with a
18 script called <tt class="docutils literal">ez_setup.py</tt> that can be used to install them.</p>
19 <div class="contents topic" id="contents">
20 <p class="topic-title first">Contents</p>
21 <ul class="simple">
22 <li><a class="reference internal" href="#cython" id="id3">Cython</a></li>
23 <li><a class="reference internal" href="#github-git-and-hg" id="id4">Github, git and hg</a></li>
24 <li><a class="reference internal" href="#id2" id="id5">Setuptools</a></li>
25 <li><a class="reference internal" href="#running-the-tests-and-reporting-errors" id="id6">Running the tests and reporting errors</a></li>
26 <li><a class="reference internal" href="#building-an-egg" id="id7">Building an egg</a></li>
27 <li><a class="reference internal" href="#building-lxml-on-macos-x" id="id8">Building lxml on MacOS-X</a></li>
28 <li><a class="reference internal" href="#static-linking-on-windows" id="id9">Static linking on Windows</a></li>
29 <li><a class="reference internal" href="#building-debian-packages-from-svn-sources" id="id10">Building Debian packages from SVN sources</a></li>
30 </ul>
31 </div>
32 <div class="section" id="cython">
33 <h1>Cython</h1>
34 <p>The lxml.etree and lxml.objectify modules are written in <a class="reference external" href="http://www.cython.org">Cython</a>.
35 Since we distribute the Cython-generated .c files with lxml releases,
36 however, you do not need Cython to build lxml from the normal release
37 sources.  We even encourage you to <em>not install Cython</em> for a normal
38 release build, as the generated C code can vary quite heavily between
39 Cython versions, which may or may not generate correct code for lxml.
40 The pre-generated release sources were tested and therefore are known
41 to work.</p>
42 <p>So, if you want a reliable build of lxml, we suggest to a) use a
43 source release of lxml and b) disable or uninstall Cython for the
44 build.</p>
45 <p><em>Only</em> if you are interested in building lxml from a checkout of the
46 developer sources (e.g. to test a bug fix that has not been release
47 yet) or if you want to be an lxml developer, then you do need a
48 working Cython installation.  You can use <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">EasyInstall</a> to install it:</p>
49 <pre class="literal-block">
50 easy_install "Cython&gt;=0.14.1"
51 </pre>
52 <p>lxml currently requires Cython 0.14.1, later release versions should
53 work as well.</p>
54 </div>
55 <div class="section" id="github-git-and-hg">
56 <h1>Github, git and hg</h1>
57 <p>The lxml package is developed in a repository on <a class="reference external" href="https://github.com/lxml/">Github</a> using
58 <a class="reference external" href="http://mercurial.selenic.com/">Mercurial</a> and the <a class="reference external" href="http://hg-git.github.com/">hg-git</a> plugin.  You can retrieve the current
59 developer version using:</p>
60 <pre class="literal-block">
61 hg clone git://github.com/lxml/lxml.git lxml
62 </pre>
63 <p>This will create a directory <tt class="docutils literal">lxml</tt> and download the source into it,
64 including the complete development history.  Don't be afraid, the
65 download is fairly quick.  You can also browse the <a class="reference external" href="https://github.com/lxml/lxml">lxml repository</a>
66 through the web.</p>
67 </div>
68 <div class="section" id="id2">
69 <h1>Setuptools</h1>
70 <p>Usually, building lxml is done through setuptools.  Clone the source
71 repository as described above (or download the <a class="reference external" href="https://github.com/lxml/lxml/tarball/master">source tar-ball</a> and
72 unpack it) and then type:</p>
73 <pre class="literal-block">
74 python setup.py build
75 </pre>
76 <p>or:</p>
77 <pre class="literal-block">
78 python setup.py bdist_egg
79 </pre>
80 <p>If you want to test lxml from the source directory, it is better to build it
81 in-place like this:</p>
82 <pre class="literal-block">
83 python setup.py  build_ext -i
84 </pre>
85 <p>or, in Unix-like environments:</p>
86 <pre class="literal-block">
87 make
88 </pre>
89 <p>If you get errors about missing header files (e.g. <tt class="docutils literal">Python.h</tt> or
90 <tt class="docutils literal">libxml/xmlversion.h</tt>) then you need to make sure the development
91 packages of Python, libxml2 and libxslt are properly installed.  On
92 Linux distributions, they are usually called something like
93 <tt class="docutils literal"><span class="pre">libxml2-dev</span></tt> or <tt class="docutils literal"><span class="pre">libxslt-devel</span></tt>.  If these packages were
94 installed in non-standard places, try passing the following option to
95 setup.py to make sure the right config is found:</p>
96 <pre class="literal-block">
97 python setup.py build --with-xslt-config=/path/to/xslt-config
98 </pre>
99 <p>If this doesn't help, you may have to add the location of the header
100 files to the include path like:</p>
101 <pre class="literal-block">
102 python setup.py build_ext -i  -I /usr/include/libxml2
103 </pre>
104 <p>where the file is in <tt class="docutils literal">/usr/include/libxml2/libxml/xmlversion.h</tt></p>
105 <p>To use lxml.etree in-place, you can place lxml's <tt class="docutils literal">src</tt> directory on your
106 Python module search path (PYTHONPATH) and then import <tt class="docutils literal">lxml.etree</tt> to play
107 with it:</p>
108 <pre class="literal-block">
109 # cd lxml
110 # PYTHONPATH=src python
111 Python 2.5.1
112 Type "help", "copyright", "credits" or "license" for more information.
113 &gt;&gt;&gt; from lxml import etree
114 &gt;&gt;&gt;
115 </pre>
116 <p>To make sure everything gets recompiled cleanly after changes, you can
117 run <tt class="docutils literal">make clean</tt> or delete the file <tt class="docutils literal">src/lxml/etree.c</tt>.  Distutils
118 do not automatically pick up changes that affect files other than the
119 main file <tt class="docutils literal">src/lxml/etree.pyx</tt>.</p>
120 </div>
121 <div class="section" id="running-the-tests-and-reporting-errors">
122 <h1>Running the tests and reporting errors</h1>
123 <p>The source distribution (tgz) and the source repository contain a test
124 suite for lxml.  You can run it from the top-level directory:</p>
125 <pre class="literal-block">
126 python test.py
127 </pre>
128 <p>Note that the test script only tests the in-place build (see distutils
129 building above), as it searches the <tt class="docutils literal">src</tt> directory.  You can use the
130 following one-step command to trigger an in-place build and test it:</p>
131 <pre class="literal-block">
132 make test
133 </pre>
134 <p>This also runs the ElementTree and cElementTree compatibility tests.  To call
135 them separately, make sure you have lxml on your PYTHONPATH first, then run:</p>
136 <pre class="literal-block">
137 python selftest.py
138 </pre>
139 <p>and:</p>
140 <pre class="literal-block">
141 python selftest2.py
142 </pre>
143 <p>If the tests give failures, errors, or worse, segmentation faults, we'd really
144 like to know.  Please contact us on the <a class="reference external" href="http://lxml.de/mailinglist/">mailing list</a>, and please specify
145 the version of lxml, libxml2, libxslt and Python you were using, as well as
146 your operating system type (Linux, Windows, MacOs, ...).</p>
147 </div>
148 <div class="section" id="building-an-egg">
149 <h1>Building an egg</h1>
150 <p>This is the procedure to make an lxml egg for your platform (assuming
151 that you have <a class="reference external" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> installed):</p>
152 <ul class="simple">
153 <li>Download the lxml-x.y.tar.gz release.  This contains the pregenerated C so
154 that you can be sure you build exactly from the release sources.  Unpack
155 them and cd into the resulting directory.</li>
156 <li>python setup.py build</li>
157 <li>If you're on a unixy platform, cd into <tt class="docutils literal">build/lib.your.platform</tt> and strip
158 any <tt class="docutils literal">.so</tt> file you find there.  This reduces the size of the egg
159 considerably.</li>
160 <li><tt class="docutils literal">python setup.py bdist_egg</tt></li>
161 </ul>
162 <p>This will put the egg into the <tt class="docutils literal">dist</tt> directory.</p>
163 </div>
164 <div class="section" id="building-lxml-on-macos-x">
165 <h1>Building lxml on MacOS-X</h1>
166 <p>Apple regularly ships new system releases with horribly outdated
167 system libraries.  This is specifically the case for libxml2 and
168 libxslt, where the system provided versions are too old to build lxml.</p>
169 <p>While the Unix environment in MacOS-X makes it relatively easy to
170 install Unix/Linux style package management tools and new software, it
171 actually seems to be hard to get libraries set up for exclusive usage
172 that MacOS-X ships in an older version.  Alternative distributions
173 (like macports) install their libraries in addition to the system
174 libraries, but the compiler and the runtime loader on MacOS still sees
175 the system libraries before the new libraries.  This can lead to
176 undebuggable crashes where the newer library seems to be loaded but
177 the older system library is used.</p>
178 <p>Apple discourages static building against libraries, which would help
179 working around this problem.  Apple does not ship static library
180 binaries with its system and several package management systems follow
181 this decision.  Therefore, building static binaries requires building
182 the dependencies first.  The <tt class="docutils literal">setup.py</tt> script does this
183 automatically when you call it like this:</p>
184 <pre class="literal-block">
185 python setup.py build --static-deps
186 </pre>
187 <p>This will download and build the latest versions of libxml2 and
188 libxslt from the official FTP download site.  If you want to use
189 specific versions, or want to prevent any online access, you can
190 download both <tt class="docutils literal">tar.gz</tt> release files yourself, place them into a
191 subdirectory <tt class="docutils literal">libs</tt> in the lxml distribution, and call <tt class="docutils literal">setup.py</tt>
192 with the desired target versions like this:</p>
193 <pre class="literal-block">
194 python setup.py build --static-deps \
195        --libxml2-version=2.7.3 \
196        --libxslt-version=1.1.24 \
197
198 sudo python setup.py install
199 </pre>
200 <p>Instead of <tt class="docutils literal">build</tt>, you can use any target, like <tt class="docutils literal">bdist_egg</tt> if
201 you want to use setuptools to build an installable egg.</p>
202 <p>Note that this also works with <a class="reference external" href="http://peak.telecommunity.com/DevCenter/EasyInstall">EasyInstall</a>.  Since you can't pass
203 command line options in this case, you have to use an environment
204 variable instead:</p>
205 <pre class="literal-block">
206 STATIC_DEPS=true easy_install lxml
207 </pre>
208 <p>Some machines may require an additional run with "sudo" to install the
209 package into the Python package directory:</p>
210 <pre class="literal-block">
211 STATIC_DEPS=true sudo easy_install lxml
212 </pre>
213 <p>The <tt class="docutils literal">STATICBUILD</tt> environment variable is handled equivalently to
214 the <tt class="docutils literal">STATIC_DEPS</tt> variable, but is used by some other extension
215 packages, too.</p>
216 </div>
217 <div class="section" id="static-linking-on-windows">
218 <h1>Static linking on Windows</h1>
219 <p>Most operating systems have proper package management that makes installing
220 current versions of libxml2 and libxslt easy.  The most famous exception is
221 Microsoft Windows, which entirely lacks these capabilities.  It can therefore
222 be interesting to statically link the external libraries into lxml.etree to
223 avoid having to install them separately.</p>
224 <p>Download lxml and all required libraries to the same directory.  The iconv,
225 libxml2, libxslt, and zlib libraries are all available from the ftp site
226 <a class="reference external" href="ftp://ftp.zlatkovic.com/pub/libxml/">ftp://ftp.zlatkovic.com/pub/libxml/</a>.</p>
227 <p>Your directory should now have the following files in it (although most likely
228 different versions):</p>
229 <pre class="literal-block">
230 iconv-1.9.1.win32.zip
231 libxml2-2.6.23.win32.zip
232 libxslt-1.1.15.win32.zip
233 lxml-1.0.0.tgz
234 zlib-1.2.3.win32.zip
235 </pre>
236 <p>Now extract each of those files in the <em>same</em> directory.  This should give you
237 something like this:</p>
238 <pre class="literal-block">
239 iconv-1.9.1.win32/
240 iconv-1.9.1.win32.zip
241 libxml2-2.6.23.win32/
242 libxml2-2.6.23.win32.zip
243 libxslt-1.1.15.win32/
244 libxslt-1.1.15.win32.zip
245 lxml-1.0.0/
246 lxml-1.0.0.tgz
247 zlib-1.2.3.win32/
248 zlib-1.2.3.win32.zip
249 </pre>
250 <p>Go to the lxml directory and edit the file <tt class="docutils literal">setup.py</tt>.  There should
251 be a section near the top that looks like this:</p>
252 <pre class="literal-block">
253 STATIC_INCLUDE_DIRS = []
254 STATIC_LIBRARY_DIRS = []
255 STATIC_CFLAGS = []
256 </pre>
257 <p>Change this section to something like this, but take care to use the correct
258 version numbers:</p>
259 <pre class="literal-block">
260 STATIC_INCLUDE_DIRS = [
261        "..\\libxml2-2.6.23.win32\\include",
262        "..\\libxslt-1.1.15.win32\\include",
263        "..\\zlib-1.2.3.win32\\include",
264        "..\\iconv-1.9.1.win32\\include"
265        ]
266
267 STATIC_LIBRARY_DIRS = [
268        "..\\libxml2-2.6.23.win32\\lib",
269        "..\\libxslt-1.1.15.win32\\lib",
270        "..\\zlib-1.2.3.win32\\lib",
271        "..\\iconv-1.9.1.win32\\lib"
272        ]
273
274 STATIC_CFLAGS = []
275 </pre>
276 <p>Add any CFLAGS you might consider useful to the third list.  Now you
277 should be able to pass the <tt class="docutils literal"><span class="pre">--static</span></tt> option to setup.py and
278 everything should work well.  Try calling:</p>
279 <pre class="literal-block">
280 python setup.py bdist_wininst --static
281 </pre>
282 <p>This will create a windows installer in the <tt class="docutils literal">pkg</tt> directory.</p>
283 </div>
284 <div class="section" id="building-debian-packages-from-svn-sources">
285 <h1>Building Debian packages from SVN sources</h1>
286 <p><a class="reference external" href="http://thread.gmane.org/gmane.comp.python.lxml.devel/1239/focus=1249">Andreas Pakulat</a> proposed the following approach.</p>
287 <ul class="simple">
288 <li><tt class="docutils literal"><span class="pre">apt-get</span> source lxml</tt></li>
289 <li>remove the unpacked directory</li>
290 <li>tar.gz the lxml SVN version and replace the orig.tar.gz that lies in the
291 directory</li>
292 <li>check md5sum of created tar.gz file and place new sum and size in dsc file</li>
293 <li>do <tt class="docutils literal"><span class="pre">dpkg-source</span> <span class="pre">-x</span> <span class="pre">lxml-[VERSION].dsc</span></tt> and cd into the newly created directory</li>
294 <li>run <tt class="docutils literal">dch <span class="pre">-i</span></tt> and add a comment like "use trunk version", this will
295 increase the debian version number so apt/dpkg won't get confused</li>
296 <li>run <tt class="docutils literal"><span class="pre">dpkg-buildpackage</span> <span class="pre">-rfakeroot</span> <span class="pre">-us</span> <span class="pre">-uc</span></tt> to build the package</li>
297 </ul>
298 <p>In case <tt class="docutils literal"><span class="pre">dpkg-buildpackage</span></tt> tells you that some dependecies are missing, you
299 can either install them manually or run <tt class="docutils literal"><span class="pre">apt-get</span> <span class="pre">build-dep</span> lxml</tt>.</p>
300 <p>That will give you .deb packages in the parent directory which can be
301 installed using <tt class="docutils literal">dpkg <span class="pre">-i</span></tt>.</p>
302 </div>
303 </div>
304 <div class="footer">
305 <hr class="footer" />
306 Generated on: 2012-07-31.
307
308 </div>
309 </body>
310 </html>