阅读量:0
Could not build the ssl module!
基于源码安装python 3.12,执行make
出现如下错误
_hashlib _ssl _tkinter To find the necessary bits, look in configure.ac and config.log. Could not build the ssl module! Python requires a OpenSSL 1.1.1 or newer Checked 111 modules (31 built-in, 76 shared, 1 n/a on linux-x86_64, 0 disabled, 3 missing, 0 failed on import)
问题大概描述:找不到ssl模块。该问题如果不解决的话,缺少 OpenSSL 模块可能会影响许多涉及网络通信和安全加密的 Python 应用程序和库。例如:ssl,request模块等好多模块都没法使用。所以要要去openssl官网下载安装,再来安装python。
openssl 官网
注意:最新的稳定版本是3.2系列,支持到2025年11月23日。3.1系列支持到2025年3月14日,3.0系列是一个长期支持(LTS)版本,支持到2026年9月7日。所有旧版本(包括1.1.1、1.1.0、1.0.2、1.0.0和0.9.8)现在都不支持,不应该使用。建议这些旧版本的用户尽快升级到3.2或3.0。对1.1.1和1.0.2的扩展支持可以访问这些版本的安全修复程序。
版本推荐
虽然openssl官网推荐最新版本,但是安装python,执行make依然会报错,我建议下载安装python3.12时推荐的openssl 1.1.1版本。
[root@iZwz98v1pircy9j9329rhrZ local]# pwd /usr/local [root@iZwz98v1pircy9j9329rhrZ local]# ll total 60 drwxr-xr-x 8 root root 4096 Apr 4 20:22 aegis drwxr-xr-x. 2 root root 4096 Apr 4 20:21 bin drwxr-xr-x. 2 root root 4096 Apr 11 2018 etc drwxr-xr-x. 2 root root 4096 Apr 11 2018 games drwxr-xr-x. 4 root root 4096 Apr 4 19:07 include drwxr-xr-x. 5 root root 4096 Apr 4 20:02 lib drwxr-xr-x. 6 root root 4096 Apr 4 17:16 lib64 drwxr-xr-x. 2 root root 4096 Apr 11 2018 libexec drwxr-xr-x 7 root root 4096 Apr 4 19:33 openssl1.1.1w 【可以】 drwxr-xr-x 9 root root 4096 Apr 4 20:50 openssl3.0.1 【不可以】 drwxr-xr-x 7 root root 4096 Apr 4 18:58 openssl3.2.1 【不可以】 drwxr-xr-x. 2 root root 4096 Apr 11 2018 sbin drwxr-xr-x. 8 root root 4096 Apr 4 17:17 share drwxr-xr-x. 2 root root 4096 Apr 11 2018 src drwxr-xr-x 5 root root 4096 Apr 4 17:16 ssl
安装openssl
- openssl找到1.1.1版本
- 下载上传到服务器
[root@iZwz98v1pircy9j9329rhrZ ~]# ll total 1112740 -rw-r--r-- 1 root root 1069373440 Apr 4 14:47 mysql-8.3.0-1.el7.x86_64.rpm-bundle.tar -rw-r--r-- 1 root root 9893384 Apr 4 19:29 openssl-1.1.1w.tar.gz drwxrwxr-x 21 root root 4096 Apr 4 20:29 openssl-3.0.13 -rw-r--r-- 1 root root 15294843 Apr 4 17:03 openssl-3.0.13.tar.gz drwxrwxr-x 26 root root 4096 Apr 4 20:50 openssl-3.2.1 -rw-r--r-- 1 root root 17733249 Apr 4 14:23 openssl-3.2.1.tar.gz drwxr-xr-x 18 root root 4096 Apr 4 21:38 Python-3.12.2 -rw-r--r-- 1 root root 27116462 Apr 4 15:01 Python-3.12.2.tgz
- 解压
[root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]# tar -zxvf openssl-1.1.1w.tar.gz``` 4. 进入目录 ```bash [root@iZwz98v1pircy9j9329rhrZ ~]# cd openssl-1.1.1w/ [root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]#
- 运行配置文件,指定安装路径,安装到/usr/local/openssl目录下
[root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]# ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib Operating system: x86_64-whatever-linux2 Configuring OpenSSL version 1.1.1w (0x1010117fL) for linux-x86_64 Using os-specific seed configuration Creating configdata.pm Creating Makefile ********************************************************************** *** *** *** OpenSSL has been successfully configured *** *** *** *** If you encounter a problem while building, please open an *** *** issue on GitHub <https://github.com/openssl/openssl/issues> *** *** and include the output from the following command: *** *** *** *** perl configdata.pm --dump *** *** *** *** (If you are new to OpenSSL, you might want to consult the *** *** 'Troubleshooting' section in the INSTALL file first) *** *** *** ********************************************************************** [root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]#
- 编译
[root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]# make
- 安装
[root@iZwz98v1pircy9j9329rhrZ openssl-1.1.1w]# make install
- 切换目录/usr/bin,备份原始的openssl
[root@iZwz98v1pircy9j9329rhrZ bin]# mv openssl openssl.bak [root@iZwz98v1pircy9j9329rhrZ bin]# pwd /usr/bin [root@iZwz98v1pircy9j9329rhrZ bin]# ll | grep openssl -rwxr-xr-x 1 root root 555280 Mar 21 2023 openssl.bak
- 创建软连接,使执行openssl时使用新版本的openssl
[root@iZwz98v1pircy9j9329rhrZ bin]# ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl [root@iZwz98v1pircy9j9329rhrZ bin]# ll | grep openssl lrwxrwxrwx 1 root root 30 Apr 4 18:52 openssl -> /usr/local/openssl/bin/openssl -rwxr-xr-x 1 root root 555280 Mar 21 2023 openssl.bak
- 将安装路径添加到环境变量
export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH
[root@iZwz98v1pircy9j9329rhrZ ~]# pwd /root [root@iZwz98v1pircy9j9329rhrZ ~]# cat .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH [root@iZwz98v1pircy9j9329rhrZ ~]#
- 运行 source .bashrc 的目的是重新加载当前用户的 .bashrc 文件,以便应用其中所做的更改,而无需注销并重新登录。
[root@iZwz98v1pircy9j9329rhrZ ~]# source .bashrc
- 更新共享库的链接器缓存
[root@iZwz98v1pircy9j9329rhrZ ~]# ldconfig
- 检查是否安装成功
[root@iZwz98v1pircy9j9329rhrZ ~]# openssl version OpenSSL 1.1.1w 11 Sep 2023
安装python
官网下载python最新版本,我选择3.12版本
上传到服务器
[root@iZwz98v1pircy9j9329rhrZ ~]# ll total 1112736 -rw-r--r-- 1 root root 1069373440 Apr 4 14:47 mysql-8.3.0-1.el7.x86_64.rpm-bundle.tar drwxrwxr-x 19 root root 4096 Apr 4 22:00 openssl-1.1.1w -rw-r--r-- 1 root root 9893384 Apr 4 19:29 openssl-1.1.1w.tar.gz drwxrwxr-x 21 root root 4096 Apr 4 20:29 openssl-3.0.13 -rw-r--r-- 1 root root 15294843 Apr 4 17:03 openssl-3.0.13.tar.gz drwxrwxr-x 26 root root 4096 Apr 4 20:50 openssl-3.2.1 -rw-r--r-- 1 root root 17733249 Apr 4 14:23 openssl-3.2.1.tar.gz -rw-r--r-- 1 root root 27116462 Apr 4 15:01 Python-3.12.2.tgz
- 解压
[root@iZwz98v1pircy9j9329rhrZ ~]# tar -zxvf Python-3.12.2.tgz
- 进入解压好的文件,执行配置文件,安装到/usr/local/python3.12
[root@iZwz98v1pircy9j9329rhrZ Python-3.12.2]# ./configure --prefix=/usr/local/python3.12 --with-openssl=/usr/local/openssl
- 编译
[root@iZwz98v1pircy9j9329rhrZ Python-3.12.2]# make
- 安装
[root@iZwz98v1pircy9j9329rhrZ Python-3.12.2]# make install
- 检查是否安装成功
[root@iZwz98v1pircy9j9329rhrZ bin]# /usr/local/python3.12/bin/python3.12 Python 3.12.2 (main, Apr 4 2024, 22:39:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>> >```