Centos7 安装 python3
系统版本
[root@localhost Python-3.7.1]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
安装环境依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel -y
解压安装文件
tar -xvf Python-3.7.1.tar.xz
cd Python-3.7.1
./configure prefix=/usr/local/python3
make && make install
配置环境变量
echo “export PATH=$PATH:/usr/local/python3/bin/" >> /etc/profile
source /etc/profile
#将原来的链接备份
[root@localhost ~]# mv /usr/bin/python /usr/bin/python.bak
#添加python3的软链接
[root@localhost ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python
测试是否安装成功了
[root@localhost ~]# python -V
Python 3.7.1
更改yum配置,否则会导致yum不能正常使用
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把#! /usr/bin/python 修改为#! /usr/bin/python2