get errors when import lxml.etree to python

后端 未结 3 656
挽巷
挽巷 2020-12-03 18:20

i have installed an lxml on my mac, when i type in python like this

localhost:lxml-3.0.1 apple$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
         


        
相关标签:
3条回答
  • 2020-12-03 19:07

    Run the following command to install the lxml package.

    pip install lxml --user 
    

    should fix the issue. I tested it on MAC OSX 10.7.5, it worked fine.

    0 讨论(0)
  • 2020-12-03 19:18

    If you've installed libxml2, then it's possible that it's just not picking up the right version (there's a version installed with OS X by default). In particular, suppose you've installed libxml2 to /usr/local. You can check what shared libraries etree.so references:

    $> otool -L /Library/Python/2.7/site-packages/lxml-3.2.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so 
    /Library/Python/2.7/site-packages/lxml-3.2.1-py2.7-macosx-10.7-intel.egg/lxml/etree.so:
        /usr/lib/libxslt.1.dylib (compatibility version 3.0.0, current version 3.24.0)
        /usr/local/lib/libexslt.0.dylib (compatibility version 9.0.0, current version 9.17.0)
        /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    

    Checking for that symbol in the system-installed version:

    $> nm /usr/lib/libxml2.2.dylib | grep ___xmlStructuredErrorContext
    

    For me, it's not present in the system-installed library. In the version I installed, however:

    $> nm /usr/local/lib/libxml2.2.dylib | grep ___xmlStructuredErrorContext
    000000000007dec0 T ___xmlStructuredErrorContext
    

    To solve this, make sure your install path appears first in DYLD_LIBRARY_PATH:

    $> export DYLD_LIBRARY_PATH=/usr/local/lib
    $> python
    >>> from lxml import etree
    # Success!
    
    0 讨论(0)
  • 2020-12-03 19:22

    I had the same problem. If you have installed it with pip as follows: pip install lxml

    Instead, try to use

    STATIC_DEPS=true pip install lxml
    

    This solved the problem for me.

    Found at this website

    0 讨论(0)
提交回复
热议问题