我已经使用自制软件安装了python 3,然后安装了pip3和lxml。
以下一行
来自lxml import entree
导致以下错误:
$ 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();
有人知道如何解决这个问题吗?
答案 0 :(得分:0)
我已从
删除了所有版本的python /Library/Frameworks/Python.framework/Versions/
之后我使用brew重新安装了python 3并使用
重新创建了符号链接 brew link --overwrite python3
答案 1 :(得分:0)
删除lxml并重新安装lxml第二次为我工作(很奇怪,不满意这个解决方案):
pip3.4 uninstall lxml
pip3.4 install lxml
pip3抱怨已安装lxml,请使用以下命令手动删除安装文件:
rm -fr /private/var/folders/dj/saljfdsf12_sd7s89dfg9080000rb/T/pip_build_user/lxml
然后再说:
pip3.4 install lxml
它有效。我无法重现原始错误消息以找到此问题的根本原因。
答案 2 :(得分:0)
如果您使用Homebrew并安装了xz
,则以下内容应该有效:
STATIC_DEPS=true CFLAGS=-I/usr/local/include/lzma pip install -U lxml
否则将CFLAGS设置为lzma标题所在的位置。
答案 3 :(得分:0)
我有同样的问题,
我做了什么:
首先,我确保我没有安装端口py27-xml2
,py27-xslt
或py27-lxml
sudo port installed | grep py27
我安装了端口py27-pip
并检查了$ PATH变量指向它。还安装了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
然后我使用easy_install安装了lxml
,该目录与pip
STATIC_DEPS=true sudo easy_install-2.7 lxml
构建过程显示:
$ 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
我在$ PATH的末尾移动了MAMP(似乎已经附带了这些库),卸载了lxml
(显示“找不到符号:_lzma_auto_decoder”错误)并重复上一个命令:
$ 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
这修复了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
>>>