Python3.7安裝(解決ssl問題)


注:本博文主要為轉載后根據本人情況再加工

1 問題:

python3.7.2安裝遇到如下ssl問題

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'

2 解決辦法

  2.1安裝依賴

        yum groupinstall development

  2.2 安裝libressl代替openssl-devel 

    2.2.1 原因

      由於系統的openssl是1.0.1的版本,對於python3.7太老了,需要更新為openssl1.0.2或者libressl2.64(不含)以后的版本,所以這里從libressl官網下載libressl源碼,編譯生成庫文件代替系統的openssl1.0.1

    2.2.2 安裝libressl

    下載libressl-2.8.0

./config –prefix=/usr/local/libressl 
make 
make intall

mv /usr/bin/openssl /usr/bin/openssl.bak 
mv /usr/include/openssl /usr/include/openssl.bak 
ln -s /usr/local/libressl/bin/openssl /usr/bin/openssl 
ln -s /usr/local/libressl/include/openssl /usr/include/openssl

  2.2.3 加載lib

cd /etc/ld.so.conf.d
新建文件
vim libressl-2.8.0.conf
#將以下行加入文件,並保存
/usr/local/libressl/lib

ldconfig -v #重新加載庫文件

2.3安裝python3.7

從官網下載python3.7的源碼,
解壓后進入Python-3.7.0

編譯前需要設置環境變量(重要)
export LDFLAGS="-L/usr/local/libressl/lib"
export CPPFLAGS="-I/usr/local/libressl/include"
export PKG_CONFIG_PATH="/usr/local/libressl/lib/pkgconfig"

./configure –prefix=/usr/local/python3 –enable-shared CFLAGS=-fPIC
運行后會出現一堆信息:
注意最后的ssl檢查,如下圖所示:

2.4 處理異常

  運行python3.7命令遇到:libpython3.7m.so.1.0: cannot open shared object file: No such file or d

 echo /usr/local/python3.7/lib > /etc/ld.so.conf.d/python3.7.conf

 ldconfig -v

 2.4 驗證

 

 https://blog.csdn.net/love_cjiajia/article/details/82254371

linux下gunicorn+flask項目的部署

https://blog.csdn.net/m0_38124502/article/details/78685941


免責聲明!

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



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