upgrade you python to 3.5.2 on CentOS 7 and fix the yum

CentOS7use the python2.7.5 as default, you should pay acctention to two thing when upgrading the  python to 3.5.2

  1. update the python link in the default sysytem
  2. fix the yum

 

A. install the  python 3.5.2

# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
# tar -zxf Python-3.5.2.tgz

B. install the python

# cd Python-3.5.2/
# ./configure 
# make
# make install

C.  you will see this as below

# /usr/local/bin/python3.5
Python 3.5.2 (default, Jul 24 2016, 14:46:50) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

D. update the python link in the default sysytem

move and keep the old one for yum

 mv /usr/bin/python /usr/bin/python2.7.5

make link to the system default python path

# ln -s /usr/local/bin/python3.5 /usr/bin/python

you will see this below if success change defaule python to 3.5.2

[root@localhost ~]# python
Python 3.5.2 (default, Jul 24 2016, 14:46:50) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

E. you will find that yum is broken

[root@localhost ~]# yum
  File "/usr/bin/yum", line 30
    except KeyboardInterrupt, e:
                            ^
SyntaxError: invalid syntax

you can fix it by follow this:

vim /usr/bin/yum

change:

#!/usr/bin/python

to

#!/usr/bin/python2.7.5

F. All done

[root@localhost ~]# yum
Loaded plugins: fastestmirror, langpacks
You need to give some command
Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package‘s dependencies

... ...

 

版权声明:
作者:John
链接:https://vps.la/2013/11/27/upgrade-you-python-to-3-5-2-on-centos-7-and-fix-the-yum/
来源:VPS啦
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>