Cannot install Lxml on Mac OS X 10.9
Solution 1
You should install or upgrade the commandline tool for Xcode. Try this in a terminal:
xcode-select --install
Solution 2
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
Solution 3
You may solve your problem by running this on the commandline:
STATIC_DEPS=true pip install lxml
It sure helped me. Explanations on docs
Solution 4
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.
Solution 5
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
Related videos on Youtube
David O'Regan
Started with visual basic and have been chasing the high ever since. Im David, an Irish software developer from Ireland. I explain with words and code. Former head of frontend at VSWare LTD. Passionate about JavaScript, React, Functional Programming and all things maths.
Updated on July 17, 2022Comments
-
David O'Regan almost 2 years
I want to install Lxml so I can then install Scrapy.
When I updated my Mac today it wouldn't let me reinstall lxml, I get the following error:
In file included from src/lxml/lxml.etree.c:314: /private/tmp/pip_build_root/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found #include "libxml/xmlversion.h" ^ 1 error generated. error: command 'cc' failed with exit status 1
I have tried using brew to install libxml2 and libxslt, both installed fine but I still cannot install lxml.
Last time I was installing I needed to enable the developer tools on Xcode but since it's updated to Xcode 5 it doesn't give me that option anymore.
Does anyone know what I need to do?
-
Phil L. almost 10 yearsPS: I recommend using:
pip3.4 install lxml
orSTATIC_DEPS=true pip3.4 install lxml
commands if you're targeting specific installation for Python3 (adapt to your version, bash TAB completion is your friend); so that you install for the specific version of your target program that is using this/these libs. Otherwise it's easy to spend 30mn installing the lib for the wrong interpreter ;-) -
Parker over 9 yearsBe sure to mark the correct answer as the solution so others can use your question as guidance when they have the same problem :)
-
-
kelorek over 10 yearsI get "Can't install the software because it is not currently available from the Software Update server."
-
wombat about 10 yearsIt's worth noting that you seem to get "Can't install the software because it is not currently available from the Software Update server." when the tools are already installed.
-
frankV about 10 yearsthanks. this helped me. wish answers could sometimes contain meta about the os versions.
-
swandog about 10 yearsIf installing globally you may need to
/etc/sudoers
withsudo visudo
to preserve the environment variables. -
erickthered almost 10 yearsThis worked for me, had to update xcode dev tools first using: xcode-select --install
-
Steven Mercatante almost 10 yearsThis did the trick. I already had xcode command line tools installed, but looks like it needed to be updated.
-
João Pereira almost 10 yearsWorked flawless for me. +1
-
studgeek almost 10 yearsA few notes on how to manually check if they are installed - stackoverflow.com/a/20834890/255961
-
Michiel Kauw-A-Tjoe over 9 yearsThis merely disables hard errors for unused arguments, which I've encountered during many other library compilations on OS X Mavericks. I've found it useful to add the line to my bash profile, so I don't have to look it up every time I encounter it:
export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"
or you can add architecture types explicitly like this:export ARCHFLAGS="-arch x86_64 -arch i386 -Wno-error=unused-command-line-argument-hard-error-in-future"
-
Marcos Eliziário Santos over 9 yearsThe most useful answer. It's incredible how the xcode-select get so many votes. If you are using brew, you already did code-select or install xcode a long time ago.
-
Mauro Baraldi over 9 yearsThis solution works on Mavericks also! If you are using
virtualenv
no sudo is needed. -
lukecampbell over 9 yearsThank you so much. This saved me an incredibly amount of time.
-
Noach Magedman over 9 years@MarcosEliziárioSantos The word "install" in
xcode-select --install
is a bit misleading. I found that after upgrading from Mavericks to Yosemite, I needed to runxcode-select --install
again to upgrade to Yosemite's Command Line Tools. It (partially) solved problems I was running into, and in any case would be harmless to run redundantly. -
Noach Magedman over 9 yearsIt's interesting that some people needed to
sudo
the pip install while others didn't. (I had permission problems when running pip install directly, and had to sudo.) I can only assume that I had installed something python-related as root in the distant past, which created certain (system) folders as root instead of as myself. -
Kar about 9 yearsDuplicate of Andre's answer.
-
Rafal Es about 9 years@MarcosEliziárioSantos probably because top answer fixed the problem for most people. This solution worked as a workaround, but I ran into similar problems with libmemcache few seconds later. Top answer fixed the problem. Everyone should consider this method only after trying the top answer first.
-
Rafal Es about 9 years@MarcosEliziárioSantos one more thing - I am using brew but it was a fresh install (I had only XCode installed via AppStore, which is enough to install homebrew).
-
7stud about 9 yearsI had enough of homebrew creating a tangled mess of things on my old system, so I vowed not to use it with my new Yosemite 10.10.2 setup. I already installed the whole Xcode package, so no need for
xcode-select install
for me. I downloaded the latest libxml2 and libxlst packages (required for lxml), but before installing them I thought I'd check if Yosemite already has those files some where. I created a virtual env(using virtualenvwrapper), and then I didpip install lxml
, and lxml installed error free. I tested lxml by scraping google's home page, and that worked fine. -
Eric Chen about 9 yearsWorks fine on 10.10.3. Not sure why others need to manipulate cflags.
-
sudo almost 9 yearsAlso, Homebrew always ruins my permissions. I used the Xcode solution.
-
mgrandi almost 9 yearsThis worked for me, I had just set up a new mac for work and even though i installed XCode, i guess it didn't install the command line tools? Anyway, running this, having it install the tools and then just rerunning 'pip3.4 install lxml --user' worked, no sudo or EXPORTING any shell variables.
-
PLPeeters over 8 yearsMine is still outputting
OSError: [Errno 1] Operation not permitted: '/usr/bin/build'
despite running the command as sudo. Any ideas? -
robinsj over 8 years@PLPeeters Which version of python are you running and which OS version?
-
PLPeeters over 8 yearsI'm on the El Capitan beta (so that's 10.11) and using Python 2.7 for this. I'm guessing it might have something to do with El Capitan...
-
Łukasz over 8 yearsAnd worked for me after upgrade to El Capitan (10.11).
-
nils over 8 yearsThis worked perfectly on Yosemite in a virtualenv. I didn't need
sudo
though. -
jacoor over 8 yearsYou are a life saver. El capitan works, in virtualenv no sudo needed. Thanks!
-
cbmanica over 8 yearsBrew is not the right answer for everyone - did not work for me, in any case, due to permissions on /usr/local that I don't control. Thanks to the wonder of Apple, just because you installed xcode awhile ago doesn't mean you don't need to do it again.
-
Markus Amalthea Magnuson over 8 yearsI edited the answer to add a link on solving Homebrew permission errors on, especially on El Capitan.
-
sami over 8 yearson El Capitan, the following worked for me: sudo CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments pip install lxml
-
mahmoudajawad about 8 yearsIt seems that Yosemite and El Capitan are having versions of libxml2 installed under the hood that Homebrew is trying to avoid clashing with by not setting up the symlinks by default. Your "link --force" did the trick, thanks!
-
karantan almost 8 yearsworks on El Capitan. I'm using virtualenv. (sudo is probably not needed if on virtualenv)
-
Esteban almost 8 years@NoachMagedman I'm installing into a virtual environment, so I cannot use sudo. If I used sudo, it would install it into my global python packages, which is what i'm trying to avoid.
-
user9869932 over 7 yearsWorks fine on OSX 10.9.5
-
chenware over 7 yearsHad a problem installing the latest version of nokogiri and looking at the logs I found an error that looked like the above. This solution worked for me.
-
Bad Request over 7 yearsThis helped me install Nokogiri in Sierra as well.
-
Tim Strijdhorst about 6 yearsThis seems dangerous but it's the only solution that actually worked. #livinontheedge
-
DexterT. almost 6 yearsThis worked on Sierra + XCode 9, where the xcode upgrade from 8.x to 9 ruined things
-
jolvera over 5 yearsThanks! Works fine on macOS 10.14