python3.10及以上版本編譯安裝ssl模塊的詳細過程
前言
由于python3.10之后版本不在支持libressl使用ssl,需要使用openssl安裝來解決編譯安裝python時候遇到的ssl模塊導入失敗的問題,這里需要用的openssl1.1.1版本或者更高版本
編譯安裝openssl
下載地址
參見https://www.openssl.org/,包括以下版本:
https://www.openssl.org/source/openssl-3.1.0-alpha1.tar.gz
https://www.openssl.org/source/openssl-1.1.1s.tar.gz
https://www.openssl.org/source/openssl-3.0.7.tar.gz
編譯安裝
注:編譯之前請先確保系統(tǒng)中安裝了make以及gcc的軟件包。,編譯安裝前確認/usr/include/openssl//為空
tar -zxf openssl-1.1.1s.tar.gz cd openssl-1.1.1s/ ./config -fPIC --prefix=/usr/include/openssl enable-shared make make install
其中:
- l -fPIC: 位置無關(guān)代碼
- l --prefix=: 路徑 一般選 /usr/include/openssl
- l enbale-shared: 動態(tài)庫
安裝openssl3.0.7問題
安裝openssl3.0.7時候報錯,查看對應(yīng)文件顯示模塊缺少,需要加載導入模塊
報錯原因: 缺少IPC/Cmd.pm模塊
解決方法:
安裝perl-CPAN
$ yum install -y perl-CPAN
進入CPAN的she模式,首次進入需要配置shel,按照提示操作即可
$ perl -MCPAN -e shell
在shell中安裝缺少的模塊,確定是cpan[1]算是進入了操作命令入口
cpan[1]> install IPC/Cmd.pm
退出界面回到shell
cpan[1]> quit
安裝成功后,重新編譯OpenSSL即可
編譯安裝python3.11.2
下載地址
python下載地址
https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tgz
編譯安裝
需要修改解壓后的python Moudle/Setup文件
tar -xf Python-3.11.2.tar.xzcd Python-3.11.2/
需要修改解壓后的python Moudle/Setup文件
# To statically link OpenSSL: - # _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \ + _ssl _ssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \ - # -l:libssl.a -Wl,--exclude-libs,libssl.a \ + -l:libssl.a -Wl,--exclude-libs,libssl.a \ - # -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a + -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a - # _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \ + _hashlib _hashopenssl.c $(OPENSSL_INCLUDES) $(OPENSSL_LDFLAGS) \ - # -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a + -l:libcrypto.a -Wl,--exclude-libs,libcrypto.a
編譯安裝,注意configure命令
此處參考了:configure配置
chmod +x configure mkdir /usr/local/python-3.11.2 ./configure --prefix=/usr/local/python-3.11.2 --with-zlib=/usr/include/ --with-openssl-rpath=auto --with-openssl=/usr/include/openssl OPENSSL_LDFLAGS=-L/usr/include/openssl OPENSSL_LIBS=-l/usr/include/openssl/ssl OPENSSL_INCLUDES=-I/usr/include/openssl make -j 4 make install
驗證是否成功安裝ssl模塊
/usr/local/python-3.11.2/bin/python3 -V /usr/local/python-3.11.2/bin/python3 # 執(zhí)行下面命令不報錯既正常 >>import _ssl >>
總結(jié)
到此這篇關(guān)于python3.10及以上版本編譯安裝ssl模塊的文章就介紹到這了,更多相關(guān)python編譯安裝ssl模塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
pytorch保存和加載模型的方法及如何load部分參數(shù)
本文總結(jié)了pytorch中保存和加載模型的方法,以及在保存的模型文件與新定義的模型的參數(shù)不一一對應(yīng)時,我們該如何加載模型參數(shù),對pytorch保存和加載模型相關(guān)知識感興趣的朋友一起看看吧2024-03-03Kmeans聚類算法python sklearn用戶畫像教程
這篇文章主要介紹了Kmeans聚類算法python sklearn用戶畫像教程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07