I had this same issue,
What I did:
First, I ensured I did not have the ports py27-xml2
, py27-xslt
or py27-lxml
installed
sudo port installed | grep py27
I installed port py27-pip
and checked that $PATH variable pointed it. Also installed py27-setuptools
.
$ sudo port contents py27-pip | grep /pip$
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
in ~/.bash_profile:
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
$ which pip
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
Then I installed lxml
with easy_install which was located in the same directory than pip
STATIC_DEPS=true sudo easy_install-2.7 lxml
The building process was displaying:
$ STATIC_DEPS=true sudo easy_install-2.7 lxml
Searching for lxml
Reading https://pypi.python.org/simple/lxml/
Downloading
....
Building without Cython.
Using build configuration of libxslt 1.1.29
Building against libxml2/libxslt in the following directory: /Applications/MAMP/Library/
....
libxml/xmlversion.h: No such file or directory
I moved MAMP (seems to already come with those libs) at the end of $PATH, uninstalled lxml
(displayed "Symbol not found: _lzma_auto_decoder" error) and repeated last command:
$ STATIC_DEPS=true sudo easy_install-2.7 -m "lxml==3.6.4"
in ~/.bash_profile:
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}:/Applications/MAMP/Library/bin:/Applications/MAMP/Library"
$ source ~/.bash_profile
$ STATIC_DEPS=true sudo easy_install-2.7 lxml
This fixed the error either inside or outside virtualenv
$ python
Python 2.7.12 (default, Jun 29 2016, 12:46:54)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>>