1、下载python并解压
地址:https://www.python.org/ftp/python/
tar -zxvf Python-3.9.9.tgz
2、安装依赖包
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 gcc libffi-devel gcc make automake autoconf libtool libffi-devel
yum -y groupinstall "Development tools"
yum install libffi-devel -y
3、创建安装目录
mkdir /usr/local/python3
4、安装python
cd Python-3.9.9
./configure --prefix=/usr/local/python3
make && make install
出现如下输出则代表安装成功
Installing collected packages: setuptools, pip
Successfully installed pip-21.1.1 setuptools-56.0.0
5、创建软连接
查看当前python软连接
ll /usr/bin/ |grep python
删除默认软链接,配置软连接为python3
rm -rf /usr/bin/python
ln -s /usr/local/python3/bin/python3 /usr/bin/python
查看是否更改成功
[root@localhost ~]# python -V
Python 3.9.9
删除默认pip软连接,并添加pip3新的软连接
rm -rf /usr/bin/pip
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
还可以配个pip3的
ln -s /usr/local/python3/bin/pip3.9 /usr/bin/pip3
验证
[root@localhost ~]# pip3 -V
pip 21.2.4 from /usr/local/python3/lib/python3.9/site-packages/pip (python 3.9)
6、更改yum配置
将如下配置文件的 #! /usr/bin/python 都修改为 #! /usr/bin/python2
vi /usr/bin/yum
vi /usr/libexec/urlgrabber-ext-down
vi /usr/bin/yum-config-manager //这个文件如果是空的话,就随便执行一个yum安装
7、最后就可以使用python3了
0 条评论