目录
(1)报错:Could not build the ssl module!
一、环境信息
名称 | 值 |
CPU | Intel(R) Core(TM) i5-1035G1 CPU @ 1.00GHz |
操作系统 | CentOS Linux release 7.9.2009 (Core) |
内存 | 4G |
逻辑核数 | 4 |
原Python3版本 | 3.6.8 |
新Python3版本 | 3.12.4 |
二、卸载Python3
1、使用包管理器卸载
[root@czg0 openssl-1.1.1w]# yum remove python3
2、手动卸载
[root@czg0 GcdwPkg]# whereis python3
python3: /usr/bin/python3 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python3.6m-x86_64-config /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz
[root@czg0 GcdwPkg]# rm -rf /usr/bin/python3 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python3.6m-x86_64-config /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/lib/python3.6 /usr/include/python3.6m /usr/share/man/man1/python3.1.gz
三、安装Python3
1、下载Python3
(1)下载地址
(2)版本
我这边就选择最新的Python 3.12.4。
2、解压
[root@czg0 GcdwPkg]# tar -xvf Python-3.12.4.tgz
3、切换目录
[root@czg0 GcdwPkg]# cd Python-3.12.4/
[root@czg0 Python-3.12.4]# ll
总用量 1464
-rw-r--r-- 1 root root 22013 6月 7 02:26 aclocal.m4
-rwxr-xr-x 1 root root 49348 6月 7 02:26 config.guess
-rwxr-xr-x 1 root root 35276 6月 7 02:26 config.sub
-rwxr-xr-x 1 root root 872093 6月 7 02:26 configure
-rw-r--r-- 1 root root 236034 6月 7 02:26 configure.ac
drwxr-xr-x 17 root root 4096 6月 7 02:26 Doc
drwxr-xr-x 2 root root 39 6月 7 02:26 Grammar
drwxr-xr-x 4 root root 4096 6月 7 02:26 Include
-rwxr-xr-x 1 root root 15358 6月 7 02:26 install-sh
drwxr-xr-x 37 root root 8192 6月 7 02:26 Lib
-rw-r--r-- 1 root root 13936 6月 7 02:26 LICENSE
drwxr-xr-x 8 root root 164 6月 7 02:26 Mac
-rw-r--r-- 1 root root 108038 6月 7 02:26 Makefile.pre.in
drwxr-xr-x 3 root root 4096 6月 7 02:26 Misc
drwxr-xr-x 16 root root 4096 6月 7 02:26 Modules
drwxr-xr-x 4 root root 4096 6月 7 02:26 Objects
drwxr-xr-x 2 root root 285 6月 7 02:26 Parser
drwxr-xr-x 5 root root 4096 6月 7 02:26 PC
drwxr-xr-x 2 root root 8192 6月 7 02:26 PCbuild
drwxr-xr-x 2 root root 216 6月 7 02:26 Programs
-rw-r--r-- 1 root root 53474 6月 7 02:26 pyconfig.h.in
drwxr-xr-x 5 root root 4096 6月 7 02:26 Python
-rw-r--r-- 1 root root 8703 6月 7 02:26 README.rst
drwxr-xr-x 25 root root 4096 6月 7 02:26 Tools
4、配置
[root@czg0 Python-3.12.4]# ./configure --prefix=/usr/local
这里--prefix
指定了安装路径,通常为/usr/local
。
5、编译
(1)报错:Could not build the ssl module!
[root@czg0 Python-3.12.4]# make
The necessary bits to build these optional modules were not found:
_bz2 _ctypes _ctypes_test
_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, 72 shared, 1 n/a on linux-x86_64, 1 disabled, 6 missing, 0 failed on import)
截取了部分,内容太多,make提示警告,应该是系统上的OpenSSL版本太旧,不符合Python的要求。
(2)安装OpenSSL 1.1.1
参考之前的博客:《Linux-学习-05-openssl安装与卸载》
(3)安装开发工具和库
[root@czg0 Python-3.12.4]# yum groupinstall "Development Tools"
[root@czg0 Python-3.12.4]# yum install -y bzip2-devel libffi-devel readline-devel sqlite-devel tk-devel xz-devel
6、编译安装
[root@czg0 Python-3.12.4]# make install
7、创建软连接
[root@czg0 Python-3.12.4]# ln -sf /usr/local/bin/python3.12 /usr/bin/python3
[root@czg0 Python-3.12.4]# ln -sf /usr/local/bin/pip3.12 /usr/bin/pip3
8、验证
[root@czg0 Python-3.12.4]# python3 -V
Python 3.12.4