下载安装包

可以到官网 ftp 地址,复制指定 python 版本源码安装包下载链接

https://www.python.org/ftp/python/

或者到官网 downloads, 复制指定 python 版本源码安装包下载链接

https://www.python.org/downloads/source/

linux服务器上下载pthon安装包

wget https://www.python.org/ftp/python/3.10.2/Python-3.10.2.tgz

创建安装目录

mkdir -p /usr/local/python3

编译安装

解压压缩包

tar -zxf Python-3.10.2.tgz

更新下载 python 可能要用到的依赖

yum -y install gcc zlib* openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel

编译配置

# 进入python解压目录
cd Python-3.10.2/

# 配置编译安装目录
./configure --prefix=/usr/local/python3

编译安装

make && make install

建立软链接

ln -s /usr/local/python3/bin/python3.10 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.10 /usr/bin/pip3

测试

# python3 --version
Python 3.10.2

# pip3 --version
pip 21.2.4 from /usr/local/python3/lib/python3.10/site-packages/pip (python 3.10)

python3
Python 3.10.2 (main, Feb 25 2022, 18:08:32) [GCC 8.5.0 20210514 (Red Hat 8.5.0-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>