一、安装编译相关依赖
$yum update
$yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel
sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
二、 下载最新的源码包
从Python官方源中下载最新的源码包,或者从国内镜像源中下载
https://www.python.org/ftp/python/
[root@wuhu ~]# cd /usr/local/src
[root@wuhu src]# wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
[root@wuhu src]# tar -xvJf Python-3.10.0.tar.xz
三、编译安装
mkdir /usr/local/python3
cd Python-3.10.0/
./configure --prefix=/usr/local/python3
make && make install
四、建立软连接或者添加PATH
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
五、验证安装
[root@dcoker-test Python-3.10.0]# python3
Python 3.10.0 (default, Jan 20 2022, 15:58:13) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>