1. 程式人生 > 其它 >Linux安裝python3.8時,編譯過程中報錯Could not build the ssl module!

Linux安裝python3.8時,編譯過程中報錯Could not build the ssl module!

技術標籤:【-------Python------】PythonPythonssl

一、 Python編譯安裝缺失模組_ctypes

build correctly but finished with this message:

    Failed to build these modules:
    _ctypes

安裝依賴庫

sudo apt install build-essential python3-devlibffi-dev

二、在安裝Python3.8編譯時報錯:Could not build the ssl module!

Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
LibreSSL 2.6.4 and earlier do not provide the necessary APIs, 
https://github.com/libressl-portable/portable/issues/381

1.官網下載最新的openssl安裝https://www.openssl.org/source/gitrepo.html

(1)檢視openssl版本

openssl version

(2)解壓安裝包:

sudo tar -zxf openssl-1.1.1h.tar.gz


(3)進入安裝包依次執行:

./config
make
make test
make install

然後重新安裝Python3.8

BUT,依然失敗! 不能載入sslmodule

2.安裝libressl

根據錯誤提示,發現需要安裝libressl,所以需要重現下載和安裝libressl 來替代openssl

(1)下載地址:

https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz

tar zxvf libressl-2.7.4.tar.gz -C ./

cdcd libressl-2.7.4

./config --prefix=/usr/local

sudo make install

(2)新建或修改 /etc/ld.so.conf.d/local.conf 配置檔案,新增如下內容:

/usr/local/lib

然後將 /usr/local/lib 目錄加入到模組載入目錄。
重新載入共享模組:

sudo ldconfig -v

重新編譯Python3.8
回到 Python3.8目錄,編輯安裝檔案 Modules/Setup

刪除有關 ssl 編譯程式碼的註釋,共 4 行

SSL=/usr/local
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

這樣重新編譯python之後,就可以正常匯入ssl模組了

(3)驗證Python、pip、ssl

OK~ 大功告成!

三、安裝缺少的zlib庫

zipimport.ZipImportError: can't decompress data; zlib not available
Makefile:1099: recipe for target 'install' failed
make: *** [install] Error 1

安裝指令:

sudo apt install zlibc zlib1g-dev

OK~