How to install lxml on OS X Leopard without using MacPorts or Fink?

I have tried this and often run into problems in the past. Does anyone have a recipe for installing lxml on OS X without MacPorts or Fink, which definitely works?

Preferably with complete 1-2-3 steps to load and build each of the dependencies.

+36
python shell lxml osx-leopard macos
Aug 14 '09 at 10:22
source share
16 answers

Thanks to @jessenoller on Twitter, I have an answer that suits my needs - you can compile lxml with static dependencies, so avoid messing with libxml2 that comes 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 
+35
Aug 14 '09 at 11:40
source share
— -

This worked for me (10.6.8):

 sudo env ARCHFLAGS="-arch i386 -arch x86_64" easy_install lxml 
+31
Jul 01 2018-11-11T00:
source share

I had great luck with Homebrew to install the libxml2 dependency:

 brew install libxml2 

Homebrew doesn't seem to have libxslt , but I don't need XSLT yet. YMMV.

Once you have the dependency (s) then normal methods work just fine:

 pip install lxml 

or

 easy_install lxml 
+19
Apr 26 '11 at 1:32
source share

Easy_install can work with this:

STATIC_DEPS = true easy_install 'lxml> = 2.2beta4'

you may need to perform, depending on permissions;

STATIC_DEPS = true sudo easy_install 'lxml> = 2.2beta4'

see http://muffinresearch.co.uk/archives/2009/03/05/install-lxml-on-osx/

+5
Aug 26 '09 at 10:05
source share

using homegrown (0.9.5) on the el-captain (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 
+4
Jan 13 '16 at 21:36
source share

In OS X 10.9.1, the proposed answer is above error during installation - the following changes should have been 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 
+3
Feb 01 '14 at 17:54
source share

This worked for me on 10.8.5

  • Install Xcode from the Mac App Store
  • Xcode -> Settings -> Downloads -> Command Line Tools
  • Set Homebrew Using
  • ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  • brew install libxml2
  • sudo easy_install lxml

It contains suggestions from:

  • stack overflow
  • stack overflow
  • stack overflow

But I wanted to compile it in one answer, and not leave comments everywhere

+2
10 Oct '13 at 18:52
source share

This worked for me in the past to install lxml in osx

+1
Aug 14 '09 at 11:41
source share

I did a great job with Snow Lepoard, but after I switched to Lion, I had to symbolize gcc-4.2 before gcc. Running sudo env ARCHFLAGS = "- arch i386 -arch x86_64" easy_install lxml was looking for gcc-4.2 instead of gcc.

+1
Oct 21 2018-11-21T00:
source share

I use OSX 10.11 El Capitan and Homebrew. Using pip install lxml will give me a "fatal error:" libxml / xmlversion.h "file not found" and "failed with error code 1" blah blah.

According to the official website , I have to use STATIC_DEPS=true pip install lxml (add sudo to pip if you need it) and this solved my problem.

I ran brew install libxml2 and brew install libxslt to install dependencies during troubleshooting. I'm not sure if these two teams are needed.

+1
Oct 17 '15 at 1:24
source share

Try installing Cython and installing from source, easy_install does not work. I haven't tried on my mac yet though.

Otherwise, the port version will not be so ancient. You can see the dependencies, some of which need to be updated for my Linux build lxml.

info py25-lxml py25-lxml @ 2.1.5 (python, devel)

lxml is the Pythonic binding for the libxml2 and libxslt libraries. It is unique in that it combines the speed and completeness of the functions of these libraries with the simplicity of the native Python API, which is 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 Supervisors: akitada@macports.org openmaintainer@macports.org

0
Aug 14 '09 at 11:15
source share
0
Aug 14 '09 at 11:15
source share

lxml is included in the pypm repository:

 $ pypm install lxml 
0
Oct 09 '09 at 6:27
source share

To install with updated versions of libxml2 and libxslt:

 ARCHFLAGS="-arch i386 -arch x86_64" STATIC_DEPS=true pip install lxml 

To install with specific library versions:

 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 (question a bit, 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 
0
Apr 25 2018-12-21T00:
source share

A lot of pain went into it for the outdated 10.6.8 os x, but here it goes for everyone who works with Snow Leopard!

First you need to install another version of libxml2 from homebrew and install --with-python. You can do this by entering the following commands.

 brew update brew edit libxml2 

Then find the line that says "--without-python" and change it to "--with-python".

 system "./configure", "--disable-dependency-tracking", "--prefix=#{prefix}", "--with-python" 

Now you can install libxml2.

 brew install libxml2 

Next, check the new installation of libxml2 at the default source location. You want to find the libxml2 configuration.

YOURS MAY BE DIFFERENT:

"/ USR / local / Footer / libxml2 / VERSION_ / bin / xml2 configurations"

Now use the following command to install lxml using pip using the recently installed libxml2 configuration, 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. Thank you

Credit goes to this page to show me pip -install-option ...

http://natanyellin.com/page/4/

0
Jul 03 '14 at 0:55
source share

I will compile it in /usr/local without any problems.

Install Python, libxml2, libxslt and then lxml. You might need setuptools.

-5
Aug 14 '09 at 10:33
source share



All Articles