centos7 安装python3.7.1
centos7自带python2,由于执行yum需要python2,所以即使安装了python3也不能删除python2
1.安装依赖包
yum -y groupinstall "Development tools"
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 libffi-devel
2.下载自己需要的python版本,例如python3.7.1,下载要花费一段时间,要耐心等待
yum -y install wget
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
3.新建一个文件夹存放python3
mkdir /usr/local/python3
4.把安装包移动到该新建文件夹下,解压安装包,安装python3,依次执行以下命令,花费时间较长,耐心等待
mv Python-3.7.1.tar.xz /usr/local/python3
tar -xvJf Python-3.7.1.tar.xz
cd Python-3.7.1
./configure --prefix=/usr/local/python3
make
make install
5.创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.此时python3已经装好,在命令行中输入python3测试
7.修改yum配置文件,python2与python3共存
vi /usr/bin/yum
把#! /usr/bin/python修改为#! /usr/bin/python2(配置文件第一行)
同理
vi /usr/libexec/urlgrabber-ext-down
把文件里面的#! /usr/bin/python 也修改为#! /usr/bin/python2
此时完成python3安装,且实现与python2共存,保持yum命令可用
下面是Ubuntu配置:
sudo apt-get install gcc
sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev
安装好之后将一些文件开头改成系统的python版本,避免冲突
vim /usr/lib/command-not-found
vim /usr/bin/gnome-terminal