1、查看已安装的Python
1# 查看已安装的信息
2$ yum info python3
3# 查看python安装位置
4$ whereis python3
2、卸载已安装的Python环境
1# 卸载已安装的程序
2$ yum erase python3
3# 删除所有残余文件
4$ whereis python3|xargs rm -frv
5# 查看现有的python
6$ whereis python3
3、yum安装依赖环境
1$ 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
4、官网下载Python3.9.12
1$ yum -y install wget
2# 尽量使用国内镜像站点下载比较快
3$ wget https://mirrors.huaweicloud.com/python/3.9.12/Python-3.9.12.tgz
5、创建安装目录
1$ tar -zxvf Python-3.9.12.tgz -C ./
2$ cd Python-3.9.12
3$ mkdir /usr/local/python3
4$ ./configure --prefix=/usr/local/python3.9.12
5$ make && make install
6、创建软链接
1$ ln -s /usr/local/python3.9.12/bin/python3 /usr/bin/python3
2$ ln -s /usr/local/python3.9.12/bin/pip3 /usr/bin/pip3
7、测试
1$ python3 -V
2Python 3.9.12
3
4$ pip3 -V
5pip 22.0.4 from /usr/local/python3.9.12/lib/python3.9/site-packages/pip (python 3.9)
8、pip升级、换源
1# pip升级
2$ python3 -m pip install --upgrade pip
3# pip换源
4# 推荐使用清华的源,因为使用https协议
5$ pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple