centos7下将Python2.7.5升级到Python3.6.1以及再还原到2.7.5

  • 安装相关的软件包 避免出现编译出错,无法编译,升级之后无法使用等情况
[root@yuhai ~]# yum install -y zlib* readline* gcc*
#过程忽略
  •  从Python官网下载python3.6.1的安装包
[root@yuhai ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
--2017-03-22 22:04:24--  https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
Resolving www.python.org (www.python.org)... 151.101.72.223, 2a04:4e42:11::223
Connecting to www.python.org (www.python.org)|151.101.72.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22540566 (21M) [application/octet-stream]
Saving to: ‘Python-3.6.1.tgz.1’

100%[====================================================================>] 22,540,566  33.4KB/s   in 12m 14s

2017-03-22 22:16:40 (30.0 KB/s) - ‘Python-3.6.1.tgz.1’ saved [22540566/22540566]
[root@yuhai ~]# ls #由于是初次下载中断 所以二次下载的是.1结尾 

anaconda-ks.cfg Python-3.6.1.tgz Python-3.6.1.tgz.1

  • 解压安装包
[root@yuhai ~]# rm -rf Python-3.6.1.tgz                #删除初次下载中断的不完整安装包
[root@yuhai ~]# ls
anaconda-ks.cfg  Python-3.6.1.tgz.1
[root@yuhai ~]# tar xf Python-3.6.1.tgz.1              #解压安装包
[root@yuhai ~]# ls
anaconda-ks.cfg  Python-3.6.1  Python-3.6.1.tgz.1
[root@yuhai ~]# 
  • 进入目录并编译在/user/local/python3.6下
[root@yuhai Python-3.6.1]# mkdir /usr/local/python3.6
[root@yuhai Python-3.6.1]# ./configure --prefix=/usr/local/python3.6
过程省略
[root@yuhai Python-3.6.1]# make
过程省略
[root@yuhai Python-3.6.1]# make install
过程省略
  • 备份原本的python2.7.5
[root@yuhai Python-3.6.1]# mv /usr/bin/python /usr/bin/python_2.7.5
  • 把编译出来的Python3.6.1的命令创建软连接到/usr/bin/python
[root@yuhai Python-3.6.1]# ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python
  • 查看现在的Python版本
[root@yuhai Python-3.6.1]# python -V
Python 3.6.1
  • 还原到2.7.5版本
[root@a ~]# mv /usr/bin/python /usr/bin/python_3.6.1     #移动并重命名
[root@a ~]# mv /usr/bin/python_2.7.5 /usr/bin/python     #移动并重命名
[root@a ~]# python -V                                    #查看版本信息
Python 2.7.5

 

posted @ 2017-07-28 14:36  寂地沉  阅读(213)  评论(0编辑  收藏  举报