i have an error when executing “from lxml import etree” in the python command line after successfully installed lxml by pip

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

    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 

get same error again for older version 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 

回答1:

See also get errors when import lxml.etree to python

I think the key error here is this:

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

I found another person with the same problem on an lxml dev list.

Their suggestion:

You probably need to check your libxml/libxslt libraries. Make sure you have the versions required in the lxml installation instructions

Start by running

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

That will show if you have any unresolved shared libraries. You may need to install/update some packages.

Check the thread linked above for more troubleshooting tips.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!