Skip to main content

HOWTO: Install lxml on Mac OSX

lxml is a total nightmare to install on the Mac. For my own future sanity, this is how to do it.
  • Install MacPorts
  • Install libxml2: sudo port install libxml2
  • Install libxslt: sudo port install libxslt
  • Make sure DYLD_LIBRARY_PATH includes /opt/local/lib (I am a unix n00b and just edit ~/.bash_profile to have the lines:
    DYLD_LIBRARY_PATH=/opt/local/lib
    EXPORT DYLD_LIBRARY_PATH

    in it and restart the shell)
  • Get the lxml code: svn co http://codespeak.net/svn/lxml/trunk lxml
  • Install Easy_Install (surely you've done this already!)
  • Install Cython: easy_install Cython==0.9.6.12
  • In the lxml folder run python setup.py build --with-xslt-config=/opt/local/bin/xslt-config
  • Then python setup.py install
  • Look puzzled when python test.py fails utterly
  • Shrug that off quickly when lxml works generally
This is for Tiger, it may work on other versions too.

Comments

bollwyvl said…
Thanks for the recipe! Bookmarked!

Methinks

sudo port install libxlst


should read


sudo port install libxslt
Jamie said…
Thanks for this - after hours of dud XML libraries for python lxml looks great - and this was the help I needed to actually get it working.
Thanks for this, saved me some hassle!

Methinks

EXPORT DYLD_LIBRARY_PATH

should read

export DYLD_LIBRARY_PATH