CentOS7中的python版本為python2.7.5,升級到最新版的python時需要注意兩個問題
- 新版的python安裝好后要修改python的系統默認指向問題
- 升級到最新版python后yum報錯的問題
下面對新版的安裝步驟進行說明。
一、下載並安裝最新版python
1.下載並解壓
# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz # tar -zxf Python-3.5.2.tgz
2.安裝Python
# cd Python-3.5.2/# ./configure
# make
# make install
查看是否安裝成功
# /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.
>>>
3.修改python的系統默認指向,修改軟鏈接
正常情況下,新版本的python安裝后系統等其他應用指向的python環境依然是老版本的python,
如果刪除老版本后再裝新版本會面臨很多難以定位的麻煩,所以通常的做法是:
老版本依然保留,新版本並行存在。操作方法如下
(1)修改系統默認的python修改為2.7.5版本 # mv /usr/bin/python /usr/bin/python2.7.5 (2)創建軟連接使python指向新版本 # ln -s /usr/local/bin/python3.5 /usr/bin/python (3)檢測是否更新成功 [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. >>>
二、yum報錯問題解決
1.終端下輸入yum后報錯信息如下
[root@localhost ~]# yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax
2.vim /usr/bin/yum
修改python頭部python為python2.7.5
#!/usr/bin/python2.7.5 import sys try: import yum except ImportError: print >> sys.stderr, """\ There was a problem importing one of the Python modules required to run yum. The error leading to this problem was:
3.再次查看yum是否可用
[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 ... ...