1、首先安装依赖包,centos里面是-devel
yum -y groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、开始编译安装python3
去官网下载编译安装包或者直接执行以下命令下载
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
解压
tar -xvJf Python-3.7.1.tar.xz
切换进入
cd Python-3.7.1
编译安装
./configure prefix=/usr/local/python3
make && make install
安装完毕,/usr/local/目录下就会有python3了
因此我们可以添加软链到执行目录下/usr/bin
ln -s /usr/local/python3/bin/python3 /usr/bin/python(原python的软链指向Python2,直接添加会报错files exist,删除原软链,rm-f /usr/bin/python)
python -V 测试是不是python3的版本
4、因为执行yum需要python2版本,所以我们还要修改yum的配置,执行:
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2
同理 vi /usr/libexec/urlgrabber-ext-down 文件里面的#! /usr/bin/python 也要修改为#! /usr/bin/python2
这样python3版本就安装完成;同时python2也存在
python -V 版本3
python2 -V 版本2
标签:bin,python,devel,centos7,yum,usr,安装,python3 From: https://www.cnblogs.com/wjsqqj/p/17187437.html