pycurl安装失败报FileNotFoundError: [Errno 2] No such file or directory: 'curl-config'

作者:邓聪聪

操作系统:CentOS7.6  64位
Python版本:3.6
安装pycurl的时候报错:

[root@cm01 software]# pip3 install pycurl
Collecting pycurl
Using cached pycurl-0.3.9.tar.gz
...
Collecting pycurl (from pycurl)
Using cached pycurl-7.43.0.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "/tmp/pip-build-7572xl8l/pycurl/setup.py", line 104, in configure_unix
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/local/python3/lib/python3.6/subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "/usr/local/python3/lib/python3.6/subprocess.py", line 1333, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'curl-config'

...
__main__.ConfigurationError: Could not run curl-config: [Errno 2] No such file or directory: 'curl-config'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7572xl8l/pycurl/

到"curl-config"这个文件,网上查下发现是因为CentOS自带的curl版本过低,
ok升级一下curl版本,这里选取与pycurl相同的版本,后来发现版本就算不同也是可以的
升级安装curl

wget https://curl.haxx.se/download/curl-7.43.0.tar.gz
tar -xf curl-7.43.0.tar.gz
cd curl-7.43.0
./configure
make && make install

vi /etc/profile.d/curl.sh
export PATH=$PATH:/usr/local/curl/bin/

source /etc/profile

测试:curl -V

[root@localhost ~]# curl -V
curl 7.43.0 (x86_64-unknown-linux-gnu) libcurl/7.43.0 OpenSSL/1.0.2k zlib/1.2.7
Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: IPv6 Largefile NTLM NTLM_WB SSL libz UnixSockets 

此时再安装pycurl就成功了。

这个时候还有一个小问题,你在使用Python进行import的时候可能是报下面的错误

[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycurl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: pycurl: libcurl link-time version (7.19.7) is older than compile-time version (7.43.0)
>>>

虽然curl已经升级了,但是libcurl库里还没有升级,把原来的删除,再做一下软链接就行
libcurl库的前缀是libcurl.so

LD_LIBRARY_PATH=/usr/local/lib

 

删除原来的libcurl库软链接

rm -f /usr/lib64/libcurl.so.4*

ll /usr/local/lib/ | grep curl

在lib64目录下创建软链接指定libcurl.so库
ln -s /usr/local/lib/libcurl.so.4.3.0 /usr/lib64/libcurl.so.4.3.0
ln -s /usr/local/lib/libcurl.so.4.3.0 /usr/lib64/libcurl.so.4

 

posted @ 2019-10-31 14:47  邓聪聪  阅读(2542)  评论(0编辑  收藏  举报