Pat*_*t B 5 python homebrew lxml pip libxml2
我一直在努力做到from lxml import etree(import lxml顺便说一下工作正常)错误是:
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so
Run Code Online (Sandbox Code Playgroud)
我使用pip来安装lxml,并使用正确的架构重新安装libxml2(或者我认为)...有没有人有关于如何修复/诊断这个的想法?我是64位python
Ned*_*ily 12
lxml对于它使用的第三方库有点挑剔,它通常需要比Apple提供的版本更新的版本.建议您阅读并按照此处的说明lxml从Mac OS X上的源代码构建,包括构建自己的静态链接库.这应该工作.(我有点意外的是,自制软件还没有lxml配方.)
更新:根据您评论中的有限信息,很难确切地知道发生了什么.我怀疑你没有使用你认为的Python版本.有多种方法可以成功安装lxml; 这是问题的一部分:有太多的选择.而不是试图调试你的设置,这可能是使用Apple提供的系统Python 2.7在10.7上获得工作lxml的最简单方法.
$ sudo STATIC_DEPS=true /usr/bin/easy_install-2.7 lxml
Run Code Online (Sandbox Code Playgroud)
然后你应该能够使用lxml.etree这种方式:
$ /usr/bin/python2.7
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>> etree.__file__
'/Library/Python/2.7/site-packages/lxml-2.3.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so'
>>>
Run Code Online (Sandbox Code Playgroud)
我注意到lxml静态构建过程不会产生有效的通用构建.您可能会在lxml安装过程中看到这样的消息:
ld: warning: ignoring file /private/tmp/easy_install-83mJsV/lxml-2.3.1/build/tmp/libxml2/lib/libxslt.a, file was built for archive which is not the architecture being linked (i386)
Run Code Online (Sandbox Code Playgroud)
假设您的计算机上的默认体系结构是64位,如果您尝试以32位模式运行:
$ arch -i386 /usr/bin/python2.7
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:06)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] 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/Python/2.7/site-packages/lxml-2.3.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
Referenced from: /Library/Python/2.7/site-packages/lxml-2.3.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/lxml-2.3.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so
>>> ^D
Run Code Online (Sandbox Code Playgroud)
并且您最初报告的错误消息!因此,其根本原因似乎libxml2是lxml构建的静态库(等)不是通用的.只要您不需要lxml在32位进程中使用(大多数用途不太可能),这应该不是问题.有可能你最初使用的Python是一个只有32位的Python; 这与您报告的其他一些消息一致.
| 归档时间: |
|
| 查看次数: |
7255 次 |
| 最近记录: |