您的位置:首页 > 运维架构 > Linux

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

2017-03-23 00:00 681 查看
摘要: 时间:忘却至2017.6.17

安装相关的软件包 避免出现编译出错,无法编译,升级之后无法使用等情况

[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’

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’ saved [22540566/22540566]

[root@yuhai ~]# ls
anaconda-ks.cfg  Python-3.6.1.tgz


解压安装包

[root@yuhai ~]# tar xf Python-3.6.1.tgz             #解压安装包
[root@yuhai ~]# ls
anaconda-ks.cfg  Python-3.6.1  Python-3.6.1.tgz


进入目录并编译在/user/local/python3.6下

[root@localhost ~]# cd Python-3.6.1
[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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息