macos - 通过pip成功安装lxml后,在python命令行中执行 "from lxml import etree"时出现错误

标签 macos python-2.7 lxml llvm-gcc elementtree

    bash-3.2$ pip install lxml-2.3.5.tgz 
    Unpacking ./lxml-2.3.5.tgz
      Running setup.py egg_info for package from file:///Users/apple/workspace/pythonhome/misc/lxml-2.3.5.tgz
        Building lxml version 2.3.5.
        Building with Cython 0.17.
        Using build configuration of libxslt 1.1.27
        Building against libxml2/libxslt in the following directory: /usr/local/lib

        warning: no previously-included files found matching '*.py'
    Installing collected packages: lxml
      Running setup.py install for lxml
        Building lxml version 2.3.5.
        Building with Cython 0.17.
        Using build configuration of libxslt 1.1.27
        Building against libxml2/libxslt in the following directory: /usr/local/lib
        skipping 'src/lxml/lxml.etree.c' Cython extension (up-to-date)
        building 'lxml.etree' extension
        llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/usr/local/include -I/usr/local/include/libxml2 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace
        llvm-gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.etree.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.6-intel-2.7/lxml/etree.so
        skipping 'src/lxml/lxml.objectify.c' Cython extension (up-to-date)
        building 'lxml.objectify' extension
        llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/usr/local/include -I/usr/local/include/libxml2 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.objectify.c -o build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.objectify.o -w -flat_namespace
        llvm-gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.objectify.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.6-intel-2.7/lxml/objectify.so

    Successfully installed lxml
    Cleaning up...
    bash-3.2$ python
    Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import lxml
    >>> import html
    Traceback (most recent call last):
      File "", line 1, in 
    ImportError: No module named html
    >>> from lxml import html
    Traceback (most recent call last):
      File "", line 1, in 
      File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/html/__init__.py", line 12, in 
        from lxml import etree
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so, 2): Symbol not found: _exsltDateXpathCtxtRegister
      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

旧版本lxml2.3.4再次出现同样的错误


    bash-3.2$ pip install lxml-2.3.4.tgz 
    Unpacking ./lxml-2.3.4.tgz
      Running setup.py egg_info for package from file:///Users/apple/workspace/pythonhome/misc/lxml-2.3.4.tgz
        Building lxml version 2.3.4.
        Building with Cython 0.17.
        Using build configuration of libxslt 1.1.27
        Building against libxml2/libxslt in the following directory: /usr/local/lib

        warning: no previously-included files found matching '*.py'
    Installing collected packages: lxml
      Running setup.py install for lxml
        Building lxml version 2.3.4.
        Building with Cython 0.17.
        Using build configuration of libxslt 1.1.27
        Building against libxml2/libxslt in the following directory: /usr/local/lib
        skipping 'src/lxml/lxml.etree.c' Cython extension (up-to-date)
        building 'lxml.etree' extension
        llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/usr/local/include -I/usr/local/include/libxml2 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace
        llvm-gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.etree.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.6-intel-2.7/lxml/etree.so
        skipping 'src/lxml/lxml.objectify.c' Cython extension (up-to-date)
        building 'lxml.objectify' extension
        llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/usr/local/include -I/usr/local/include/libxml2 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.objectify.c -o build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.objectify.o -w -flat_namespace
        llvm-gcc-4.2 -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/src/lxml/lxml.objectify.o -L/usr/local/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.6-intel-2.7/lxml/objectify.so

    Successfully installed lxml
    Cleaning up...
    bash-3.2$ python
    Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> import lxml
    >>> from lxml import etree
    Traceback (most recent call last):
      File "", line 1, in 
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so, 2): Symbol not found: _exsltDateXpathCtxtRegister
      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

最佳答案

另见 get errors when import lxml.etree to python

我认为这里的关键错误是:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so, 2): Symbol not found: _exsltDateXpathCtxtRegister

我找到了 another person with the same problem on an lxml dev list .

他们的建议:

您可能需要检查您的 libxml/libxslt 库。确保您拥有 lxml installation instructions 中所需的版本

从运行开始

ldd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so

这将显示您是否有任何未解析的共享库。您可能需要安装/更新一些软件包。

查看上面链接的线程以获取更多故障排除提示。

关于macos - 通过pip成功安装lxml后,在python命令行中执行 "from lxml import etree"时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13358842/

相关文章:

Python pickle : Unclear "AttributeError: can' t set attribute"

node.js - 在 OSX 上通过 Homebrew 安装没有 Node 的 io.js 和 npm

Python 启动器 Mac

python - Python Flask 单元测试中登录测试失败

python - 我应该使用线程还是进程?

python - python中的lxml,从url解析

linux - 防止文件系统中的 Unix 域套接字文件在套接字绑定(bind)时被删除

Excel for mac 隐藏功能区

python - 如何使用 html5lib 解析 HTML,并使用 XPath 查询解析后的 H​​TML?

python - 选择其子/孙/..包含具有指定模式的元素的元素