1. 修改yum源

[root@centos ~]# yum install epel-release   
[root@centos ~]# sed -e 's!^metalink=!#metalink=!g' \
>     -e 's!^#baseurl=!baseurl=!g' \
>     -e 's!https\?://download\.fedoraproject\.org/pub/epel!https://mirrors.tuna.tsinghua.edu.cn/epel!g' \
>     -e 's!https\?://download\.example/pub/epel!https://mirrors.tuna.tsinghua.edu.cn/epel!g' \
>     -i /etc/yum.repos.d/epel*.repo
[root@centos ~]# yum makecache
[root@centos ~]# yum -y install ansible
[root@centos ~]# ansible --version

2. 安装依赖

sudo 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 gcc

3. 下载包并安装

Python华为镜像包:https://mirrors.huaweicloud.com/python/

wget https://mirrors.huaweicloud.com/python/3.9.10/Python-3.9.10.tgz
tar -zxvf Python-3.9.10.tgz

配置安装路径,配置的是/usr/local/python3

cd Python-3.9.10
./configure prefix=/usr/local/python3

编译安装

make && make install

添加软连接

ln -s /usr/local/python3/bin/python3.9 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3
# 报错文件存在则执行下面删除
rm -rf /usr/bin/python3

检查安装

python3 -V

# 设置pip清华源
pip3 config set global.index-url -i https://pypi.tuna.tsinghua.edu.cn/simple