[Centos7]安装pycurl

1.安装环境:Centos7.2+python3.6

PycURl是一个C语言写的libcurl的python绑定库。libcurl 是一个自由的,并且容易使用的用在客户端的 URL 传输库。

2.yum安装libcurl-devel
yum install libcurl-devel
3.下载curl
wget https://curl.haxx.se/download/curl-7.61.0.tar.gz
4.解压
tar -zxvf curl-7.61.0.tar.gz
5.到解压后的curl文件夹中,进行编译安装
cd curl-7.61.0/
./configure
make && make install
export LD_LIBRARY_PATH=/usr/local/lib
6.pip安装完成
pip3 install pycurl
关于运行脚本后的报错:
ImportError: pycurl: libcurl link-time version (7.29.0) is older than compile-time version (7.61.0)

解决方法:

cp /usr/local/lib/libcurl.so /usr/lib64/
编译安装pycurl

按照以上方式安装完成之后,假如在python2环境下可以正常import,但是在python3环境下报错:ModuleNotFoundError: No module named ‘pycurl’

处理方法如下:
1.查看curl版本
curl -V
#显示版本为:curl 7.61.0
2.查看旧版本
rpm -qa curl
#显示版本为:curl-7.29.0-51.el7.x86_64
3.卸载旧版本
rpm -e --nodeps curl-7.29.0-51.el7.x86_64
rpm -qa curl
export LD_LIBRARY_PATH=/usr/local/lib
echo $?
0
4.卸载pycurl
 pip uninstall pycurl
5.下载pycurl安装包
wget https://pypi.python.org/packages/source/p/pycurl/pycurl-7.43.0.3.tar.gz
6.开始安装pycurl
tar -zxvf pycurl-7.43.0.3.tar.gz
cd pycurl-7.43.0.3/
python setup.py install --curl-config=/usr/local/bin/curl-config
7.进行import测试
[root@mail pycurl-7.43.0.3]# python
Python 3.6.0 (default, Sep 20 2019, 20:23:48) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
>>>

发表评论