I\'ve tried this and run in to problems a bunch of times in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink that definitely works?<
Thanks to @jessenoller on Twitter I have an answer that fits my needs - you can compile lxml with static dependencies, hence avoiding messing with the libxml2 that ships with OS X. Here's what worked for me:
cd /tmp
curl -O http://lxml.de/files/lxml-3.6.0.tgz
tar -xzvf lxml-3.6.0.tgz
cd lxml-3.6.0
python setup.py build --static-deps --libxml2-version=2.7.3 --libxslt-version=1.1.24
sudo python setup.py install
This worked for me (10.6.8):
sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml
I had this working fine with Snow Lepoard but after I upgraded to Lion I had to symlink gcc-4.2 to gcc. Running sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml was looking for gcc-4.2 instead of gcc.
I've had excellent luck with Homebrew to install the libxml2
dependency:
brew install libxml2
Homebrew doesn't seem to have libxslt
available, but I've not yet had a need for XSLT. YMMV.
Once you have the dependency(s), then the usual methods work just fine:
pip install lxml
or
easy_install lxml
This is quite up to date - march 2009: http://lsimons.wordpress.com/2008/08/31/how-to-install-lxml-python-module-on-mac-os-105-leopard/
using homebrew (0.9.5) on el capitan (10.11.1) the following worked for me:
brew install libxml2
LD_FLAGS=-L/usr/local/opt/libxml2/lib CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 pip install lxml