1. 程式人生 > 實用技巧 >deepin python3.8 安裝三方庫請求ssl的報錯和openssl編譯升級

deepin python3.8 安裝三方庫請求ssl的報錯和openssl編譯升級

問題:

  在安裝完python3.8後,安裝第三方庫出現報錯:Can't connect to HTTPS URL because the SSL module is not available. - skipping

   查看了自身的openssl版本,1.1.1算是比較新的了,那麼問題就是python3.8在安裝的時候沒有找到openssl.而自帶的openssl卻找不到真正的路徑,所以需要重新安裝到指定目錄。

下載安裝openssl: 

 1 # 備份老版本的openssl
 2 which openssl
 3 /usr/bin/openssl
 4 mv /usr/bin/openssl /usr/bin/openssl.old
5 rm -rf /etc/ssl/ 6 7 # 安裝新版本openssl 8 wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz 9 tar -zxvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g 10 ./config --prefix=/usr/local/openssl 11 make && make install 12 ln -s /usr/local/openssl/bin/openssl /usr/local/bin/openssl 13 cp -r /usr/local/bin/openssl /usr/bin/ 14
openssl version -a

重新編譯python3.8:

  進入python3的原始碼目錄:

  vi Python-3.8.0/Modules/Setup

  按/查詢_ssl,將如下部分程式碼的註釋#去掉,wq儲存,配置一定要是自己的openssl執行檔案路徑(預設是/usr/local/ssl,我這裡修改了) 

1 # Socket module helper for socket(2)
2 _socket socketmodule.c
3 
4 # Socket module helper for SSL support; you must comment out the other
5 # socket line above, and possibly edit the SSL variable: 6 SSL=/usr/local/openssl 7 _ssl _ssl.c \ 8 -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ 9 -L$(SSL)/lib -lssl -lcrypto

  改完之後再進行編譯安裝:

1 ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
2 make && make install

  完成之後測試: