Linux编译安装安Python3.73.8出现_ssl模块错误| python运行ssl模块出现ModuleNotFoundError

Linux编译安装安Python3.73.8出现_ssl模块错误| python运行ssl模块出现ModuleNotFoundError,第1张

概述背景: 今天在Linux上使用paramiko模块的时候,出现了错误:ModuleNotFoundError:No module name '_ssl',但是我的系统是安装了opens 背景:

今天在linux上使用paramiko模块的时候,出现了错误:@H_301_4@ModuleNotFoundError:No module name '_ssl',但是我的系统是安装了openssl的1.0.1的,查了网络上的信息发现,python3.7以后的版本,需要openssl1.0.2+,或者libressl2.6.4+。

按照网络上的方法,安装了openssl-1.1.1g,对python3.8重新手动编译安装,但是在执行make命令的时候仍旧提示_ssl模块没有被成功导入。经过查询,发现是@H_301_4@LDFLAGS,CPPFLAGS,PKG_CONfig_PATH这几个环境变量的问题。

 

LDFLAGS:gcc 等编译器会用到的一些优化参数,也可以在里面指定库文件的位置。用法:LDFLAGS=-L/usr/lib -L/path/to/your/lib。每安装一个包都几乎一定的会在安装目录里建立一个lib目录。如果明明安装了某个包,而安装另一个包时,它愣是说找不到,可以把那个包的lib路径加入的LDFALGS中试一下。

CPPFLAGS:CXXFLAGS=$CFLAGS 。CFLAGS 表示用于 C 编译器的选项,CXXFLAGS 表示用于 C++ 编译器的选项。这两个变量实际上涵盖了编译和汇编两个步骤。大多数程序和库在编译时默认的优化级别是”2″(使用”-O2″选项)并且带有调试符号来编 译,也就是 CFLAGS=”-O2 -g”,.

PKG_CONfig_PATH:它指定pkg-config将在其中搜索其.pc文件的其他路径。此变量用于增强pkg-config的默认搜索路径。在典型的Unix系统上,它将搜索目录/usr/lib/pkgconfig/usr/share/pkgconfig。这通常包括系统安装的模块。但是,某些本地模块可能安装在不同的前缀中,例如/usr/local。在这种情况下,必须预先设置搜索路径,以便pkg-config可以找到.pc文件。pkg-config程序用于检索有关系统中已安装库的信息。 pkg-config的主要用途是提供编译程序和链接到库的必要细节。此元数据存储在pkg-config文件中。这些文件具有后缀.pc,并位于pkg-config工具已知的特定位置。

 

 还有可能在使用pip安装的时候,@H_301_4@报错ssl module in Python is not available,这些本质上都是因为Python在编译安装的时候,没有找到合适版本的ssl导致的。解决方案都是一样的。

 1 [root@localhost ~]# /usr/local/python3/bin/pip3 install paramiko 2 pip is configured with locations that require TLS/SSL,however the ssl module in Python is not available. 3 Collecting virtualenv 4   retrying (Retry(total=4,connect=None,read=None,redirect=None,status=None)) after connection broken by 'SSLError("Can't connect to httpS URL because the SSL module is not available.")': /simple/virtualenv/ 5   retrying (Retry(total=3,1)"> 6   retrying (Retry(total=2,1)"> 7   retrying (Retry(total=1,1)"> 8   retrying (Retry(total=0,1)"> 9   Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: httpSConnectionPool(host='pypi.org',port=443): Max retrIEs exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to httpS URL because the SSL module is not available.")) - skipPing10   Could not find a version that satisfIEs the requirement virtualenv (from versions: )11 No matching distribution found for virtualenv12 pip is configured with locations that require TLS/SSL,1)">13 Could not fetch URL https:pypi.org/simple/pip/: There was a problem confirming the ssl certificate: httpSConnectionPool(host='pypi.org',port=443): Max retrIEs exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to httpS URL because the SSL module is not available.")) - skipPing

 

解决方案:

需要升级openssl版本>=1.0.2或者libressl>=2.6.4,然后对python3.8重新编译安装。

 

1.下载openssl最新版本
1 wget https:www.openssl.org/source/openssl-1.1.1g.tar.gz

 

2.编译安装openssl
 1 tar -zxvf openssl-1.1.1g.tar.gz  #解压 2  3 cd openssl-1.1.1g 4  5 ./config –prefix=/usr/local/openssl   no-zlib #安装到这个路径 6  7  8 make 9 10 make install

 

3.备份原来的配置
 mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl/ /usr/include/openssl.bak

 

4.配置新版本的链接
1 #将安装好的openssl 的openssl命令软连到/usr/bin/openssl2 ln -s /usr/local/openssl/include/openssl /usr/include/3 4 #软链到升级后的libssl.so5 ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so6 7 #将安装好的openssl命令软连到/usr/bin/8 ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

 

5.修改系统配置
1 #写入openssl库文件的搜索路径echo /usr/local/openssl/lib" >> /etc/ld.so.conf4 #使修改后的/etc/.so.conf生效 5 ldconfig -v

 

6.查看openssl版本
openssl version

如果安装成功的话,这时候会显示你安装的版本。

 

7. 配置环境变量
1     export LDFLAGS= -L/usr/local/openssl/lib"2     export CPPFLAGS= -I/usr/local/openssl/include3     export PKG_CONfig_PATH=/usr/local/openssl/lib/pkgconfig"

 

8.解压python安装包,执行configure文件
1 ./configure --enable-shared  --with-openssl=/usr/local/openssl

这时候需要检查一下最后的ssl配置是否正常,

 

 

9.安装Python
2 3 install

 

 

10.验证是否成功

 

 现在已经不报错了,说明安装成功了。

 

总结

以上是内存溢出为你收集整理的Linux编译安装安Python3.7/3.8出现_ssl模块错误| python运行ssl模块出现ModuleNotFoundError全部内容,希望文章能够帮你解决Linux编译安装安Python3.7/3.8出现_ssl模块错误| python运行ssl模块出现ModuleNotFoundError所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1013661.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存