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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM