我使用 homebrew 安装了 python 3,然后安装了 pip3 和 lxml。
以下行
从 lxml 导入主菜
导致以下错误:
$ 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();
有人知道如何解决这个问题吗?
我已经从
删除了所有版本的python /Library/Frameworks/Python.framework/Versions/
之后我使用brew重新安装了python 3并使用
重新创建了符号链接 brew link --overwrite python3
第二次删除 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
它奏效了。我无法重现原始错误消息以找到此问题的根本原因。
如果您使用 Homebrew 并安装了
xz
,则以下操作应该有效:
STATIC_DEPS=true CFLAGS=-I/usr/local/include/lzma pip install -U lxml
否则将 CFLAGS 设置为 lzma 标头所在的位置。
我也遇到了同样的问题,
我做了什么:
首先,我确保我没有安装端口
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
我将 MAMP (似乎已经带有这些库)移到了 $PATH 的末尾,卸载了
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
>>>
面临类似问题:
ImportError: dlopen(.../python3.11/site-packages/lxml/etree.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_exsltDateXpathCtxtRegister'
我发现的唯一解决方法是卸载 lxml 并使用 conda 重新安装:
$ conda activate my_env
$ pip uninstall lxml
$ conda install -c conda-forge lxml