pycurl 安装

来源 https://blog.csdn.net/daerzei/article/details/79409656

一 报错信息

[root@cm01 software]# pip3 install pyspider
Collecting pyspider
  Using cached pyspider-0.3.9.tar.gz
...
Collecting pycurl (from pyspider)
  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/

 

二 因为CentOS自带的curl版本过低,升级curl

# 第一步:下载curl
wget https://curl.haxx.se/download/curl-7.43.0.tar.gz

#第二步: 解压
tar -zxf curl-7.43.0.tar.gz

#第三步:编译
cd curl-7.43.0
./configure

# 第四步:安装
make && make install

第五步:添加环境变量
vim /etc/profile 
# 添加下面的环境变量
export PATH=$PATH:/usr/local/curl/bin/

# 第六步:使环境变量生效
source /etc/profile

 

三 测试是否安装成功

curl -V

 

 

四 此时安装pycurl

pip3 install pycurl

 

测试是否安装成功

[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)
>>>

 

报错信息:

 pycurl: libcurl link-time version (7.19.7) is older than compile-time version (7.43.0)

 

分析:

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

 

解决办法:(重新构建curl软链)

#删除原来的libcurl库软链接
rm -f /usr/lib64/libcurl.so.4*

#查看新安装的lib
 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

 

再次导入pycurl模块就正常了

 

 

测试pycurl代码:

import pycurl
from io import BytesIO

buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://pycurl.io/')
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()

body = buffer.getvalue()
print(body.decode('iso-8859-1'))

 

posted @ 2020-03-03 11:19  柳帅  阅读(2092)  评论(0编辑  收藏  举报
//替换成自己路径的js文件