国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【python】linux系統(tǒng)python報錯“ssl module in Python is not available”

這篇具有很好參考價值的文章主要介紹了【python】linux系統(tǒng)python報錯“ssl module in Python is not available”。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、問題現象

1.1 執(zhí)行pip命令報錯

pip安裝時遇到openssl問題,沒辦法安裝第三方庫

“WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.?”【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

1.2?導入import? ssl 報錯

直接執(zhí)行python,進入python, 輸入import? ssl ,也會報相似的錯誤。?

【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

正常情況下,是這樣的,導入成功無報錯

【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

1.3 執(zhí)行python腳本報錯

【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

二、問題原因

根據出錯信息提示分析:ssl模塊不可用。

pip默認的安裝源https://pypi.org/simple/,采用的是 HTTPS協議,連接是需要SSL庫加密和解密。出錯信息顯示,你的Python沒有所需的ssl模塊。官網下載的Python已經內建了ssl模塊,應該不會出現這個問題。

2.1 openssl版本低

系統(tǒng)版本centos7.4,其中openssl的版本為OpenSSL?1.0.2k-fips,而python3.11需要的openssl的版本為1.1.x及以上,需要對openssl進行升級,并重新編譯python3.11(yum?安裝的openssl?版本都比較低)。現在有些高版本的linux,openssl已經是1.1.x版本以上,不會出現該opensll版本問題。

【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

2.3 openssl配置問題

已經源碼編譯安裝了高版本的openssl,由于沒有配置軟鏈接、和openssl庫的位置,導致的問題。

三、解決方案?

3.1 版本低-做OpenSSL升級

3.1.1 直接yum安裝高版本的openssl?

yum install -y openssl openssl-libs  openssl-devel openssl-static 
#查看版本
openssl version

3.1.2 源碼安裝openssl升級(推薦)

wget  https://www.openssl.org/source/old/1.1.1/openssl-1.1.1q.tar.gz
tar -zxvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config --prefix=/usr/local/openssl
make -j8
make install

#設置軟連接到新版本openssl
ln -sf /usr/local/bin/openssl /usr/bin/openssl
ln -sf /usr/local/include/openssl /usr/include/openssl
#openssl庫位置配置
ln -sf /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -sf /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1


echo "/usr/local/lib/" >> /etc/ld.so.conf
ldconfig -v

openssl version
openssl version -a

但是安裝好之后,還可能出現以下問題

openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory?,這是由于openssl庫的位置不正確造成的。

解決方法:以root用戶下執(zhí)行:

ln?-s? ? /usr/local/lib64/libssl.so.1.1? ? ? ? ? /usr/lib64/libssl.so.1.1
ln?-s? ? /usr/local/lib64/libcrypto.so.1.1? ? /usr/lib64/libcrypto.so.1.1

?我本機安裝的情況:【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip


3.2 配置問題-補充配置

#設置軟連接到新版本openssl
ln -sf /usr/local/bin/openssl /usr/bin/openssl
ln -sf /usr/local/include/openssl /usr/include/openssl

#openssl庫位置配置
ln -sf /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -sf /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

看到有的網上說做環(huán)境變量配置,但是?感覺做軟鏈接更清晰、簡單點。就不談環(huán)境變量配置了。

四、本人采取的方式(不推薦)

參考博主方法https://www.cnblogs.com/miyuanbiotech/p/12307875.html?,也能解決,

但是它是在編譯時,可以直接將ssl模塊編譯進去。如果在安裝其他版本的python到本機,不將openssl高版本編譯進去,還是不能用。 所以推薦使用上面(三、解決方案)的方法解決該問題。

現在有些高版本的linux,openssl已經是1.1.x版本以上,不會出現該opensll版本問題。

4.1 包下載和安裝路徑配置

wget -c https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
tar -xvf Python-3.8.1.tgz
cd Python-3.8.1
./configure --prefix=/my/path/python/
# 配置環(huán)境后先別急著編譯

4.2?Modules/Setup文件修改

SSL=/my/path/openssl  #改為剛安裝的ssl路徑
_ssl _ssl.c \
       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
       -L$(SSL)/lib -lssl -lcrypto

4.3 編譯安裝

make && make install

此時如果直接make編譯,仍會報如下類似錯誤:./python: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory generate-posix-vars failed make: *** [pybuilddir.txt] Error 1?缺少庫文件,說明libssl.so.1.1這個庫沒有讀取到。解決方法:有的是以root身份添加軟鏈接。有的將openssl庫加入環(huán)境變量。這個博主選擇了后者。

#執(zhí)行該命令 添加環(huán)境變量
export LD_LIBRARY_PATH=/my/path/openssl-1.1/lib:$LD_LIBRARY_PATH

(此處說一個比較坑的事)

環(huán)境變量配置,雖然運行python、和python腳本都沒問題。但是做定時任務crontab?時,由于找不到openssl庫,任務跑不起來。害自己排錯好久,才找到這個原因。最后重新做了?openssl庫文件的軟連接。
ln?-sf?/usr/local/lib64/libssl.so.1.1?/usr/lib64/libssl.so.1.1
n?-sf?/usr/local/lib64/libcrypto.so.1.1?/usr/lib64/libcrypto.so.1.1

4.4 測試SSL模塊

?該現象說明問題解決了。【python】linux系統(tǒng)python報錯“ssl module in Python is not available”,python,linux,pip

五、知識拓展

centos7系統(tǒng)默認安裝了python2.X,后續(xù)可能又安裝了python3.X版本,所以在控制臺輸入命令進行查看當前機器上安裝python情況。因為centos7部分模塊依賴于2.X,所以為了不引起某些麻煩,選擇不去卸載2.X,直接安裝3.X。文章來源地址http://www.zghlxwxcb.cn/news/detail-832917.html

# 查看2.x版本情況
python --version 
或
python -V

# 查看3.x版本情況
python3 --version
python3 -V?和python

到了這里,關于【python】linux系統(tǒng)python報錯“ssl module in Python is not available”的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • 報錯:__dirname is not defined in ES module scope

    報錯:__dirname is not defined in ES module scope

    ?在給vite+vue3.0設置別名的時候,直接使用了__dirname這個內置變量報錯 __dirname is not defined in ES module scope 報錯原因:? __dirname是commonjs規(guī)范的內置變量。如果使用了esm,是不會注入這個變量的。 在commonjs中,注入了__dirname,__filename, module, exports, require五個內置變量用于實現導入導

    2024年02月10日
    瀏覽(20)
  • 解決報錯: require is not defined in ES module scope

    解決報錯: require is not defined in ES module scope

    用node啟動mjs文件報錯:require is not defined in ES module scope 現象如下: ?原因: 文件后綴是mjs, 被識別為es模塊,但是node默認是commonjs格式,不支持也不能識別es模塊。 解決辦法:把文件后綴從.mjs改成 ==》.cjs后綴 補充資料: .cjs 代表使用 CommonJS 模塊 .mjs 代表使用 ES 模塊 首先我

    2024年02月08日
    瀏覽(22)
  • python報錯:tesseract is not installed or it‘s not in your PATH.

    python報錯:tesseract is not installed or it‘s not in your PATH.

    問題 :pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in your PATH. 1 電腦安裝tesseract tesseract下載地址 一路默認安裝,最后安裝地址選擇了D盤 配置path環(huán)境變量 cmd中 輸入tesseract,安裝成功 2 python 依賴包 還是報錯 File “D:anacondaLibsite-packagespytesseractpytesse

    2024年02月03日
    瀏覽(16)
  • Python報錯ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the ‘ssl‘ module is compil

    Python報錯ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the ‘ssl‘ module is compil

    運行openai模塊時,報錯 ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the ‘ssl’ module is compiled with LibreSSL 2.8.3. 可以在解釋器中將urllib3指定版本號

    2024年02月11日
    瀏覽(19)
  • 解決報錯:Can‘t connect to HTTPS URL because the SSL module is not available.

    解決報錯:Can‘t connect to HTTPS URL because the SSL module is not available.

    本人今天準備打開Pycharm安裝一個label-studio包,試了很多次,接連報如下錯誤,因此我就去找了一些解決方案,現在總結如下: github上有對應的解決方案,鏈接:https://github.com/conda/conda/issues/8273 說的是D:Anaconda3DLLs ssl.pyd search for the OpenSSL DLLs but in the wrong/current location,也就是

    2024年02月15日
    瀏覽(47)
  • windows: pip install 報錯SSLError Can‘t connect to HTTPS URL because the SSL module is not available

    windows anaconda pip清華源 通過pip install 安裝不成功,會報錯(Caused by SSLError(\\\"Can\\\'t connect to HTTPS URL because the SSL module is not available.\\\")) 錯誤詳情如下: 具體是什么錯誤什么原因導致,不去深究了?;蛟S是源本身有問題?下面直接提供解決方法,通過更換源解決了該錯誤 加上--truste

    2024年02月15日
    瀏覽(22)
  • uview-ui報錯:Component is not found in path node-modules/uview-ui/components/xx/xx

    解決方法: 1、uview-ui如果是npm安裝 需要在pages.json中添加easycom配置 2、配置了以上還報錯的話可能是 tempalte樣式最外層沒用標簽包括著(只允許有一層用 view/view 包裹最外層) 3、如果試過方法還沒解決的話,可以試試徹底 關閉開發(fā)者工具關閉,重啟 如你還有其他更好的解決

    2024年02月11日
    瀏覽(24)
  • uni-app項目使用uview-ui報錯:Component is not found in path node-modules/uview-ui/components/xx/xx

    解決: 一、uview-ui如果是 npm 安裝 需要在 pages.json 中添加 easycom 配置 二、配置了以上還報錯的話可能是 tempalte 樣式最外層沒用標簽包括著(只允許有一層 用 view/view 包裹最外層

    2024年02月11日
    瀏覽(18)
  • 完美解決:Python3.10報錯 No module named ‘_ssl‘

    完美解決:Python3.10報錯 No module named ‘_ssl‘

    報錯詳情: 操作系統(tǒng)為centos7,python版本為3.10.7,openssl版本為3.0.5,運行gunicorn報No module named \\\'_ssl\\\' 原因就是python3.10和openssl3.0.5的版本配置文件跟以前有點區(qū)別,python3.10的版本OPENSSL不再是/usr/local/ssl 的默認路徑,變成了/path/to/openssl/directory,已經提示得很明白了讓你在這里寫入

    2024年02月12日
    瀏覽(24)
  • ReferenceError: __dirname is not defined in ES module scope

    運行代碼 報錯: package.json 加了以下配置 1、方法一 刪除文件 package.json 中的配置項: \\\"type\\\": \\\"module\\\" 2、方法二 注意:該方法得到的是運行目錄,并不是該文件的所在目錄 ESM下,不能直接引入json文件了,需要通過文件接口讀取解析 參考 https://stackoverflow.com/questions/8817423/why-i

    2024年02月11日
    瀏覽(19)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包