1、下载python包
下载python3.9.6的源码包
python下载

 下载后,解压,目录如下:
-rw-------.  1 root   root         1454 Aug 26  2023 anaconda-ks.cfg
-rw-r--r--.  1 root   root     25640094 Apr  4 21:52 Python-3.9.6.tgz
drwxrwxr-x. 17 oracle oinstall     4096 Apr  4 21:55 Python-3.9.6
drwxr-xr-x.  5 root   root           74 Apr  4 22:08 ansible
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# pwd
/root
 
2、安装
三部曲
配置(configure)
 编译(make)
 安装(make install)
进入解压目录
cd /root/Python-3.9.6
 
执行configure
./configure --prefix=/usr/local/python396
 
然后执行
make && make install
 
上述工程可能会出现缺少包的情况,取决于所在服务器的一些依赖是否完整。
3、配置环境变量
ln -s /usr/local/python396/bin/python3 /usr/bin/python3
 
4、执行
[root@localhost Python-3.9.6]# python3
Python 3.9.6 (default, Apr  4 2024, 21:55:15) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
                

















