一、下载好python版本

Index of /ftp/python/

linux主机离线安装python3环境_linux

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

二、创建文件夹

mkdir /home/python/

三、上传到主机 

四、解压

# 解压xz得到tar包
xz -d Python-3.9.8.tar.xz
# 解压tar包
tar -xvf Python-3.9.8.tar

五、指定安装路径

# 进入解压后的目录
cd Python-3.9.8
# "="后跟想把Python安装在哪的路径 
./configure --prefix=/home/python/python39

五点五、编译安装之前,要安装好一些工具

yum makecache
yum install -y net-tools
yum install openssl openssl-devel -y
yum install compat-openssl10
yum install libffi-devel 
yum install -y net-tools
yum install libffi-devel 
yum install bzip2-devel
yum install sqlite-devel
sudo yum install cmake
sudo yum groupinstall 'Development Tools'

这里有可能CMake 版本过低

sudo yum remove cmake
sudo yum install epel-release
sudo yum install cmake3
yum -y install wget

六、编译安装

make && make install

七、设置

ln -sf /usr/local/python/bin/python39 /usr/bin/python3
ln -sf /usr/local/python/bin/pip39 /usr/bin/pip3

八、环境变量

修改etc下的profile文件

PATH=/home/python/python39/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

 

linux主机离线安装python3环境_python_02

九、验证

python3 -V

linux主机离线安装python3环境_python_03