代码之家  ›  专栏  ›  技术社区  ›  MedicineMan

pip安装时出现libxml2错误

  •  1
  • MedicineMan  · 技术社区  · 10 年前

    我在安装pip安装程序时遇到了很多问题。

    大多数pip安装失败。我将在这里给出一些片段来演示,但几乎每个pip安装都以类似的方式失败。我试过一些简单的方法,比如升级pip,但到目前为止没有成功。

    我正在跑步:

     pip 8.1.2 from /Library/Python/2.7/site-packages (python 2.7)
     OSX 10.10.4 Yosemite
    

    例如,如果我尝试安装一个模块,例如一个网页抓取库,一切似乎都开始顺利:

    
    pip install scrapy
    
    

    Collecting scrapy /Library/Python/2.7/site-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning. SNIMissingWarning /Library/Python/2.7/site-packages/pip/vendor/requests/packages/urllib3/util/ssl.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Using cached Scrapy-1.1.0-py2.py3-none-any.whl Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from scrapy) Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /Library/Python/2.7/site-packages (from scrapy) Requirement already satisfied (use --upgrade to upgrade): PyDispatcher>=2.0.5 in /Library/Python/2.7/site-packages (from scrapy) Collecting parsel>=0.9.3 (from scrapy) Using cached parsel-1.0.2-py2.py3-none-any.whl Collecting lxml (from scrapy) Using cached lxml-3.6.0.tar.gz

    但后来的结局是一样的:

    
          Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
    

    细节:

    
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/Applications/MAMP/Library/include -I/Applications/MAMP/Library/include/libxml2 -Isrc/lxml/includes -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.10-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace
      In file included from src/lxml/lxml.etree.c:320:
      src/lxml/includes/etree_defs.h:14:10: fatal error: 'libxml/xmlversion.h' file not found
      #include "libxml/xmlversion.h"
               ^
      1 error generated.
      Compile failed: command 'cc' failed with exit status 1
      creating var
      creating var/folders
      creating var/folders/y4
      creating var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2
      creating var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2/T
      cc -I/Applications/MAMP/Library/include -I/Applications/MAMP/Library/include/libxml2 -I/usr/include/libxml2 -c /var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2/T/xmlXPathInitFfTVls.c -o var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2/T/xmlXPathInitFfTVls.o
      /var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2/T/xmlXPathInitFfTVls.c:2:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
      main (int argc, char **argv) {
      ^
      1 warning generated.
      cc var/folders/y4/5myrk5lj12990054wgpw6hmxrhplv2/T/xmlXPathInitFfTVls.o -L/Applications/MAMP/Library/lib -lxml2 -o a.out
      ld: warning: ignoring file /Applications/MAMP/Library/lib/libxml2.dylib, missing required architecture x86_64 in file /Applications/MAMP/Library/lib/libxml2.dylib (2 slices)
      Undefined symbols for architecture x86_64:
        "_xmlXPathInit", referenced from:
            _main in xmlXPathInitFfTVls.o
      ld: symbol(s) not found for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      *********************************************************************************
      Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
      Perhaps try: xcode-select --install
      *********************************************************************************
      error: command 'cc' failed with exit status 1
    
      ----------------------------------------
      Failed building wheel for lxml
    1 回复  |  直到 10 年前
        1
  •  0
  •   MedicineMan    10 年前

    好吧,我不知道这为什么行得通,但这行得通。

    我去了这里: https://www.continuum.io/downloads

    我为OSX python版本2.7安装了Anaconda。

    我打开了一个新的终端窗口,确认安装了conda,然后再次尝试使用pip。一切都修好了。不知道这为什么有效,但它对我有效。