Mac终端安装lxml失败

安装lxml,出现错误

sudo pip install lxml
Collecting lxml
Downloading lxml-3.6.0.tar.gz (3.7MB)
100% |████████████████████████████████| 3.7MB 157kB/s 
Installing collected packages: lxml
Running setup.py install for lxml ... error

解决方法

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/MacOSX10.11.sdk/usr/include

pip install lxml

Installing collected packages: lxml
Running setup.py install for lxml ... done
Successfully installed lxml-3.6.0`

同样的,如果需要设置libpath,也在pip之前加入C_LIB_PATH再使用pip.