系统相关
首页 > 系统相关> > centos7 升级系统自带的python2.7-到python3.8.3

centos7 升级系统自带的python2.7-到python3.8.3

作者:互联网

1,python下载地址
2,安装编译环境

yum install gcc-c++ gcc make cmake zlib-devel bzip2-devel openssl-devel ncurse-devel libffi-devel -y

3,在线下载或是本地上传python3.8.3源码包

cd /henan
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz

4,解压并配置

tar -zxvf Python-3.8.2.tgz
cd Python-3.8.2
mkdir -p /usr/local/python3
./configure --prefix=/usr/local/python3
或是 ./configure --prefix=/usr/local/python3 --enable-optimizations #备注如果添加enable-optimizations  需要升级系统自带的gcc

5,编译并安装

make
make install   
#两步 echo $?  没有报错即算编译成功

6,更换系统默认python版本
备份旧版:

mv /usr/bin/python /usr/bin/python.bak
mv /usr/bin/pip /usr/bin/pip.bak

配置环境变量:创建新版本python和pip的软链接

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip

7,关键点来了
因为yum的功能依赖Pyhon2,现在更改默认Python版本后会导致yum无法正常工作,所以进行以下四处修复

标签:bin,python3,python,python2.7,devel,centos7,usr,local,python3.8
来源: https://blog.csdn.net/renren_100/article/details/122063367