pip安装成功,但下载依赖时报错the ssl module in Python is not available

问题:

执行命令,能够正确得展示pip当前版本,证明pip安装没有问题,但是使用pip下载依赖时就会报错:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

pip3 -V

问题原因:

很好理解,就是the ssl module 这个ssl模块版本太低了

python版本需要和openssl的版本需要相对匹配
在Python3.7之后的版本,依赖的openssl,必须要是1.1或者1.0.2之后的版本

解决办法:

一、先确认版本

openssl version

二、安装依赖

如果已有,这步可以忽略

yum install gcc libffi-devel zlib* openssl-devel

三、下载高版本openssl

下载:

wget https://www.openssl.org/source/openssl-3.0.1.tar.gz

解压:

tar -zxvf openssl-3.0.1.tar.gz

进入目录:

 cd openssl-3.0.1

/usr/local/openssl 这个目录要提前创建好

./config --prefix=/usr/local/openssl

四、编译&安装

编译:

make

安装:

make install

重新查看版本

openssl version

五、更新完openssl后要重新装一次python

我的安装教程:
https://blog.csdn.net/qq_38817920/article/details/129381778?spm=1001.2014.3001.5501

注意:在第三步时要加一个配置修改

执行命令:

vim Modules/Setup
按 i  按钮,进入编辑模式

修改文件内容:

找到
# Socket module helper for socket(2)
#_socket socketmodule.c
 
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#       -L$(SSL)/lib -lssl -lcrypto


改为
# Socket module helper for socket(2)
_socket socketmodule.c
 
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto
按esc退出编辑模式,直接输入  :wq!  保存编辑内容并退出

然后再按照安装教程,进行python的编译,安装。
至此,我的问题就解决了。

我很菜,希望不要误导你~~

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年5月28日
下一篇 2023年5月28日

相关推荐