版本下载位置
https://www.python.org/ftp/python
举例3.8.2版本:
1、执行下载对应版本到本地
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
2、解压版本
tar -Jxvf Python-3.8.2.tar.xz
3、设置配置文件,准备编译安装
cd Python-3.8.2
./configure prefix=/usr/local/python3 --with-ssl
ps: --with-ssl 参数必须加上,否则安装以后http请求不支持 ssl
4、将依赖全部安装一遍(偷懒全部安装,实际可以根据需要安装)
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 kernel-devel libffi-devel
5、执行编译
make && make install
6、配置软连接,考虑一般centos上有python2版本,此处pip也需要一起配置
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
7、升级PIP
pip3 install --upgrade pip
8、查看版本
[root@bz Python-3.8.2]# python3 -V
Python 3.8.2
[root@bz-server04 Python-3.8.2]# pip3 --version
pip 21.1.3 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)