Question

I have installed python 3 using homebrew and afterwards installed pip3 and lxml.

The following line

from lxml import entree

leads to the following error:

$ python3
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 01:12:57) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-  packages/lxml/etree.so, 2): Symbol not found: _lzma_auto_decoder
Referenced from: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/lxml/etree.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/lxml/etree.so
>>> exit();

Does anybody know how to fix this?

Was it helpful?

Solution

I have deleted all versions of python from

      /Library/Frameworks/Python.framework/Versions/

afterwards I have reinstalled python 3 using brew and recreated the symlinks using

     brew link --overwrite python3

OTHER TIPS

Deleting lxml and re-installing lxml a SECOND time worked for me (weird, not happy with this solution):

pip3.4 uninstall lxml
pip3.4 install lxml

pip3 complains about lxml being already installed, remove manually the install files with a command like:

rm -fr /private/var/folders/dj/saljfdsf12_sd7s89dfg9080000rb/T/pip_build_user/lxml

Then again:

pip3.4 install lxml

And it worked. I couldn't reproduce the original error message to find root cause of this problem.

If you use Homebrew and have xz installed, the following should work:

STATIC_DEPS=true CFLAGS=-I/usr/local/include/lzma pip install -U lxml

Otherwise set CFLAGS to the place where your lzma headers are located.

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
>>>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top