CentOS安装lxml
找同事要了个服务器玩玩,干净的centos(连gcc都没有),从官网下载了python3.6源码安装了
./configure
make install
默认装到了/usr/local目录下,我在config的时候添加–prefix=/usr/local/python36参数手动指定到了python36目录下。
然后因为要写爬虫嘛,我喜欢手撸,requests+lxml,贼爽
$ pip3 install requests#这里因为要和系统自带的python2共存,所以py3的pip我给重命名成pip3
$ pip3 install lxml
第一行命令没什么问题,第二行就有问题了,因为系统太干净,什么库都没有,安装lxml之前应该先安装libxml2和libxslt
$ yum install libxml2 libxml2-dev libxslt-dev
后面两个yum找不到,查找原因:
Debian系的才是libxml2-dev,RHEL系的应该是libxml2-devel
执行以下命令后成功
$ yum install libxml2 libxml2-devel libxslt-devel
然后就是安装lxml了,但是到这里直接装还是有问题,提示找不到libxml库
fatal error: libxml/xmlversion.h: No such file or directory
好气吖,我明明都install了阿。查找原因,找到了这里
原来是路径的问题,shell下先export
export C_INCLUDE_PATH=/usr/include/libxml2/
之后就是愉快的安装啦
pip3 install lxml
结果
Collecting lxml
..Using cached lxml-3.7.1.tar.gz
Building wheels for collected packages: lxml
..Running setup.py bdist_wheel for lxml … done
..Stored in director
/root/.cache/pip/wheels/90/63/7b/7def2c66617eba0de4c6ca0f3f31aa8bbffb1bb96b80fe0698
Successfully built lxml
Installing collected packages: lxml
Successfully installed lxml-3.7.1
完美~