1. 方案一: python3.8安装
1.1 下载安装包并解压缩
cd /data
wget http://cdn.npm.taobao.org/dist/python/3.8.4/Python-3.8.4.tgz
tar -zxvf Python-3.8.4.tgz
1.2 安装gcc等基础包
yum install -y gcc
yum install -y zlib*
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel libxslt-devel libsasl2-dev libsasl2-2 libsasl2-modules-gssapi-mit gcc-c++
yum -y install cyrus-sasl-devel cyrus-sasl-gssapi cyrus-sasl-md5 cyrus-sasl-plain
1.3 编译python包
cd /data/Python-3.8.4/
./configure --prefix=/usr/local/python3 --with-ssl
make
make install
1.4 进行软链接
rm -fr /usr/bin/python3 /usr/bin/pip3
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
1.5 升级pip
python3 -m pip install --upgrade pip
2. 方案二: python3.9安装
2.1 下载安装包并解压缩
下载python包,选择自己需要的版本 (Python包下载链接):https://www.python.org/ftp/python/
解压
tar -zxvf Python-3.9.18.tgz
2.2 编译&安装
# 创建一个编译、安装的文件夹
mkdir /usr/local/python39
# 编译、安装
cd Python-3.9.18
./configure --prefix=/usr/local/python39/
make && make install
安装成功
2.3 建立软连接
ln -s /usr/local/python39/bin/python3.9 /usr/bin/python39
ln -s /usr/local/python39/bin/pip3.9 /usr/bin/pip39
查验
2.4 创建python39的虚拟环境
创建:virtualenv py39 -p /usr/bin/python39
激活:source py39/bin/activate