The Python Oracle

Cannot install Lxml on Mac OS X 10.9

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Sunrise at the Stream

--

Chapters
00:00 Question
00:55 Accepted answer (Score 509)
01:11 Answer 2 (Score 197)
01:55 Answer 3 (Score 105)
02:13 Answer 4 (Score 50)
02:44 Thank you

--

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

Answer 1 links:
[this is a helpful document]: https://github.com/Homebrew/homebrew/blo...

Answer 2 links:
[docs]: http://lxml.de/installation.html#using-l...

--

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