The Python Oracle

Cannot install Lxml on Mac OS X 10.9

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Fantascape Looping

--

Chapters
00:00 Cannot Install Lxml On Mac Os X 10.9
00:45 Answer 1 Score 24
01:10 Answer 2 Score 108
01:24 Accepted Answer Score 510
01:57 Answer 4 Score 201
02:29 Thank you

--

Full question
https://stackoverflow.com/questions/1954...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #xcode #macos #scrapy #lxml

#avk47



ACCEPTED ANSWER

Score 510


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

xcode-select --install

If Xcode Command Line Tools are already installed, but you're still not able to install lxml, then reset xcode-select by following the command:

sudo xcode-select --reset

This will reset the path to the Xcode Command Line Tools directory and may resolve the issue.

After you've installed or updated Xcode Command Line Tools, Hopefully, this will resolve the issue and allow you to install the "lxml" package.




ANSWER 2

Score 201


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



ANSWER 3

Score 108


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

 STATIC_DEPS=true pip install lxml

It sure helped me. Explanations on docs




ANSWER 4

Score 24


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