how to install lxml python module on mac os 10.5 (leopard)
lxml is an xml library for python that doesn’t suck. It needs a recent libxml2 and libxslt. Mac OS X does not come with recent versions, and 10.5 breaks completely if you force it to try and use a recent version.
I used to use MacPorts for everything (which comes with py25-lxml) but ran into some issues with 10.5. So back to manual installs, it is.
- assuming your python is the mac os x default…
- make sure no traces of other pythons in your
- download and install libxml2:
./configure --prefix=/usr/local/libxml2-2.7.0 make sudo make install cd /Library/Python/2.5/site-packages sudo ln -s /usr/local/libxml2-2.7.0/lib/python2.5/site-packages/* .
- download and install libxslt:
./configure --prefix=/usr/local/libxslt-1.1.24 --with-libxml-prefix=/usr/local/libxml2-2.7.0 make sudo make install cd /Library/Python/2.5/site-packages sudo ln -s /usr/local/libxslt-1.1.24/lib/python2.5/site-packages/* .
- download and install lxml:
sudo python setup.py install \ --with-xml2-config=/usr/local/libxml2-2.7.0/bin/xml2-config \ --with-xslt-config=/usr/local/libxslt-1.1.24/bin/xslt-config
Update March 1, 2009: in order to get libxml2 and libxslt python bindings working on 10.5.6, with a python.org 2.6 version of python, I had to do quite a bit more fiddling. If the above doesn’t work for you, try this:
cd libxml2-2.7.0 autoreconf ./configure --prefix=/usr/local/libxml2-2.7.0 make sudo make install cd ../libxslt-1.1.24 autoreconf ./configure --prefix=/usr/local/libxslt-1.1.24 \ --with-python \ --with-libxml-prefix=/usr/local/libxml2-2.7.0 make sudo make install cd ../libxml2-2.7.0/python # libxml2 build doesn't support do -arch ppc export ARCHFLAGS='-arch i386' # setup.py supports libxslt install, sort-of cp ../../libxslt-1.1.24/python/libxsl* . cp ../../libxslt-1.1.24/python/generator.py xsltgenerator.py cp ../../libxslt-1.1.24/doc/libxslt-api.xml . # hack the setup.py file to learn the dir structure mv setup.py setup.py.bak curl 'http://pastebin.com/pastebin.php?dl=f158d0a96' > setup.py python setup.py build sudo python setup.py install
And then install lxml normally.
(the use of autoreconf is explained by DarwinPorts folks, the use of ARCHFLAGS is explained by apple, and the hand-editing/hand-merging of libxslt and libxml python bindings for the build based on experimental fiddling.)