安裝Python依賴包:
[root@Python src]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
下載Python原始碼包:
[root@Python src]# wget ttp://mirrors.sohu.com/python/3.6.4/Python-3.6.4.tgz
編譯、安裝:
[root@Python /]# tar -xzvf /usr/local/src/Python-3.6.4.tgz -C /usr/local/src/ [root@Python /]# cd /usr/local/src/Python-3.6.4 [root@Python Python-3.6.4]# ./configure --prefix=/usr/local/python [root@Python Python-3.6.4]# make -j 4 [root@Python Python-3.6.4]# make install
檢視擴充套件安裝包:
[root@Python /]# /usr/local/python/bin/pip3 list
pip (8.1.1) setuptools (20.10.1)
新增Python命令到環境變數:
[root@Python /]# vim ~/.bash_profile PATH=$PATH:$HOME/bin
改為:
PATH=$PATH:$HOME/bin:/usr/local/python/bin
使環境變數生效:
[root@Python /]# source ~/.bash_profile
檢視Python版本:
[root@Python /]# python3 -V Python 3.6.4
更改系統預設python版本為Python3.6
[root@Python /]# mv /usr/bin/python /usr/bin/python2.6 [root@Python /]# ln -s /usr/local/python/bin/python3.6 /usr/bin/python
核對Python版本:
[root@Python /]# python -V Python 3.6.4
解決python升級後,YUM不能正常工作的問題:
#vi /usr/bin/yum
將檔案頭部的 #!/usr/bin/python
改成 #!/usr/bin/python2.6