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?<
lxml is included in the pypm repository:
$ pypm install lxml
I'm using OSX 10.11 El Capitan and Homebrew. Using pip install lxml
would give me "fatal error: 'libxml/xmlversion.h' file not found" and "failed with error code 1" blah blah.
According to the official website, I should use STATIC_DEPS=true pip install lxml
(add sudo before pip if you need that), and that solved my problem.
I ran brew install libxml2
and brew install libxslt
to install the dependencies while troubleshooting. I'm not sure if those two commands are necessary.
Try installing Cython and installing from source, easy_install does fail. I haven't tried on my mac yet though.
Failing that the ports version isn't that ancient. You can see the dependencies, some of which had to be updated for my Linux build of lxml.
info py25-lxml py25-lxml @2.1.5 (python, devel)
lxml is a Pythonic binding for the libxml2 and libxslt libraries. It is unique in that it combines the speed and feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API. Homepage: http://codespeak.net/lxml/
Library Dependencies: python25, libxml2, libxslt, py25-hashlib, py25-setuptools, py25-zlib Platforms: darwin Maintainers: akitada@macports.org openmaintainer@macports.org
A lot of pain went into this for an outdated 10.6.8 os x but here it goes for anyone running Snow Leopard!
First you have to install a different version of libxml2 from homebrew and install --with-python. You can do this by typing in the following commands.
brew update
brew edit libxml2
Then find the line that says "--without-python" and change to "--with-python".
system "./configure", "--disable-dependency-tracking",
"--prefix=#{prefix}",
"--with-python"
Now you can install libxml2.
brew install libxml2
Next check your new install of libxml2 in the default homebrew location. You want to find the libxml2 config.
YOURS MAY BE DIFFERENT:
"/usr/local/Cellar/libxml2/VERSION_/bin/xml2-config"
Now use the following command to install lxml with pip using the newly installed libxml2 config and not the Mac OS X version.
ARCHFLAGS="-arch i386 -arch x86_64" pip install lxml --install-option="--with-xml2-config=/usr/local/Cellar/libxml2/2.9.1/bin/xml2-config"
Worked for me on my 10.6.8 Python 2.6. Thanks.
Credit goes to this page for showing me pip --install-option ...
http://natanyellin.com/page/4/
To install with up to date versions of libxml2 and libxslt:
ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml
To install with specific versions of libraries:
ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml
CentOS 64 bit (a bit off question, but hard won):
CFLAGS=-fPIC STATIC_DEPS=true pip install lxml
or
CFLAGS=-fPIC STATIC_DEPS=true LIBXML2_VERSION=2.7.3 LIBXSLT_VERSION=1.1.24 pip install lxml
On OS X 10.9.1 the suggested answer above errors out during install -- following changes had to be made:
cd /tmp
curl -o lxml-3.3.0.tgz http://lxml.de/files/lxml-3.3.0.tgz
tar -xzvf lxml-3.3.0.tgz
cd lxml-3.3.0
python setup.py build --static-deps --libxml2-version=2.8.0 --libxslt-version=1.1.24
sudo python setup.py install