Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install Lxml on Mac OS X 10.9

People also ask

How do I get LXML version?

In case you want to use the current in-development version of lxml, you can get it from the github repository at https://github.com/lxml/lxml . Note that this requires Cython to build the sources, see the build instructions on the project home page.

What is the latest version of LXML?

The latest version is lxml 4.9. 1, released 2022-07-01 (changes for 4.9. 1). Older versions are listed below.

How do I import LXML into Python?

Open your Linux terminal or shell. Type “ pip install lxml ” (without quotes), hit Enter. If it doesn't work, try "pip3 install lxml" or “ python -m pip install lxml “. Wait for the installation to terminate successfully.


You should install or upgrade the commandline tool for Xcode. Try this in a terminal:

xcode-select --install

I solved this issue on Yosemite by both installing and linking libxml2 and libxslt through brew:

brew install libxml2
brew install libxslt
brew link libxml2 --force
brew link libxslt --force

If you have solved the problem using this method but it pops up again at a later time, you might need to run this before the four lines above:

brew unlink libxml2
brew unlink libxslt

If you are having permission errors with Homebrew, especially on El Capitan, this is a helpful document. In essence, regardless of OS X version, try running:

sudo chown -R $(whoami):admin /usr/local

You may solve your problem by running this on the commandline:

 STATIC_DEPS=true pip install lxml

It sure helped me. Explanations on docs


I tried most of the solutions above, but none of them worked for me. I'm running Yosemite 10.10, the only solution that worked for me was to type this in the terminal:

sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml

EDIT: If you are using virtualenv, the sudo in beginning is not needed.


This has been bothering me as well for a while. I don't know the internals enough about python distutils etc, but the include path here is wrong. I made the following ugly hack to hold me over until the python lxml people can do the proper fix.

sudo ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2/libxml/ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml

Installing globally... OS X 10.9.2

xcode-select --install
sudo easy_install pip
sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml

instalation instructions on http://lxml.de/installation.html explain:

To speed up the build in test environments, e.g. on a continuous integration server, disable the C compiler optimisations by setting the CFLAGS environment variable:

CFLAGS="-O0" pip install lxml