1、准备一台链接外网的centos,下载python3依赖包到路径:/home/python3/
mkdir /home/python3/
yumdownloader --resolve --destdir /home/python3 zlib-devel bzip2-devel openssl-devel ncurses-devel epel-release gcc gcc-c++ xz-devel readline-devel gdbm-devel
下载安装包:(也下载到/home/python3/)
wget --no-check-certificate https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
2、离线环境安装
上传联网环境下载的东西上传到离线环境
安装依赖
cd /home/python3
rpm -Uvh ./*.rpm --nodeps --force
安装python3
tar -zxvf Python-3* #解压安装包
mkdir /usr/local/python3 # 创建编译安装目录
cd Python-3.9.5 # 进入python的解压目录
./configure --prefix=/usr/local/python3
make && make install # 编译安装
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
python3 -V
pip3 -V