Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fail to install lxml in MacOS 10.8.4

I am having trouble installing lxml to my Mac OS. I am having the following error when building it. This is the error I have when using pip install lxml

/private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml/src/lxml/includes/etree_defs.h:9:10: fatal error: 'libxml/xmlversion.h' file not found

I have installed libxml2 with brew:

brew install libxml2
brew link libxml2 --force

I'm new to Mac. In Ubuntu, it would mean libxml2-dev package must be installed.

Updated: here is the pip.log:

"~/.pip/pip.log" 124L, 8293C requirement_set.install(install_options, global_options, root=options.root_path) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 1185, in install requirement.install(install_options, global_options, *args, **kwargs) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/req.py", line 592, in install cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False) File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/util.py", line 662, in call_subprocess % (command_desc, proc.returncode, cwd)) InstallationError: Command /usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c "import setuptools;file='/private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-nsV0iT-record/install-record.txt --single-version-externally-managed failed with error code 1 in /private/var/folders/9s/s5hl5w4x7zjdjkdljw9cnsrm0000gn/T/pip-build-khuevu/lxml

Any idea ? Thanks a lot

like image 453
Khue Vu Avatar asked Jul 25 '13 12:07

Khue Vu


2 Answers

Turn out xmlversion.h is not included in compilation path even though it is in PATH. Modify the C_INCLUDE_PATH env fix the error for me:

C_INCLUDE_PATH=/usr/local/Cellar/libxml2/2.9.1/include/libxml2:$C_INCLUDE_PATH

like image 91
Khue Vu Avatar answered Sep 23 '22 13:09

Khue Vu


I have Python and libxml installed via brew, this worked for me after trying everything above:

sudo mkdir /usr/include # If /usr/include is missing
sudo ln -s /usr/local/Cellar/libxml2/2.9.2/include/libxml2 /usr/include/libxml2

Note: You'll need to check your own paths for latest versions.

Since the headers are available elsewhere, and being looked for in a particular directory (spotted in the command calling clang to compile) - and for some reason the alternate place is not being picked up, I made a softlink to the right place.

like image 29
Hiway Avatar answered Sep 22 '22 13:09

Hiway