mac pip install lxml faild --已解决

Mac终端执行pip install lxml报错:

(env) zhudeMacBook-Air:the19 zhu$ pip install lxml
Collecting lxml
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('_vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x103e4cda0>: Failed to establish a newconnection: [Errno 65] No route to host',)': /simple/lxml/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('_vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x103e492e8>: Failed to establish a newconnection: [Errno 65] No route to host',)': /simple/lxml/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('_vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x103e49390>: Failed to establish a newconnection: [Errno 65] No route to host',)': /simple/lxml/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('_vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x103e490b8>: Failed to establish a newconnection: [Errno 65] No route to host',)': /simple/lxml/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('_vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x103e49198>: Failed to establish a newconnection: [Errno 65] No route to host',)': /simple/lxml/
  Could not find a version that satisfies the requirement lxml (from versions: )
No matching distribution found for lxml

解决办法:
使用命令来设置编译的包含头文件

sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MaOSX10.11.sdk/usr/include pip install lxml

结果如下:

(env) zhudeMacBook-Air:the19 zhu$ sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MaOSX10.11.sdk/usr/include pip install lxml
The directory '/Users/zhu/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may wantsudo's -H flag.
The directory '/Users/zhu/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's-H flag.
Collecting lxml
  Downloading lxml-4.0.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (8.7MB)
    100% |████████████████████████████████| 8.7MB 94kB/s
Installing collected packages: lxml
Successfully installed lxml-4.0.0

你可能感兴趣的:(python3,爬虫)