编译安装python3.7的步骤
1.下载python3源码包
wget https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tgz
2.下载python3编译的依赖包
yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
3.解压缩源码包
tar -zxvf Python-3.7.6.tgz
4.进入源码包文件夹
#创建目录
mkdir -p /usr/local/python3
#配置(指定安装目录)
./configure --prefix=/usr/local/python3 --enable-optimizations
5.编译及安装
make&&makeinstall
6.更换系统默认Python版本
1).备份原系统旧版本python
mv /usr/bin/python /usr/bin/python.bak
2).创建新版本Python3.7的软链接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python
3).查看Python版本
python -V
7.修改yum功能
因为yum的功能依赖Pyhon2,现在更改默认Python版本后会导致yum无法正常工作,所以进行以下修复
vim /usr/bin/yum
将/usr/bin/python改为/usr/bin/python2.7
vim /usr/bin/yum-config-manager(centos找不到可以跳过此步骤)
将/usr/bin/python改为/usr/bin/python2.7
vim /usr/libexec/urlgrabber-ext-down
将/usr/bin/python改为/usr/bin/python2.7
再重新执行yum命令