CentOS 7系統自帶了python2,不過能夠不用2版本,直接使用python3運行python腳本就能夠,可是千萬別去動系統自帶的python2,由於有程序依賴目前的python2環境,好比yum,動了yum就沒法運行了,其餘有的程序也可能會受影響。明白了上面的,而後就來安裝Python3.6:html
安裝步驟:python
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develsql
https://www.python.org/downloads/vim
1
|
# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
|
包安裝在/usr/local/Python3(具體安裝位置看我的喜愛)
建立目錄:bash
1
|
# mkdir -p /usr/local/Python3
|
解壓下載好的Python-3.6.5.tgz包(具體包名因你下載的Python具體版本,我下載的是Python3.6.5這里就以Python-3.6.5.tgz爲例)spa
1
|
# tar -zxvf Python-3.6.5.tgz
|
若是編譯安裝過程有報錯提示看個人另外一個隨筆寫的解決辦法http://www.cnblogs.com/shwee/p/9013851.html3d
1
2
|
# cd Python-3.6.5
# ./configure --prefix=/usr/local/Python3
|
而後:makecode
1
|
# make
|
接着:make installsqlite
1
|
# make install
|
或者兩步一塊兒:make && make installhtm
1
|
# ln -s /usr/local/Python3/bin/python3 /usr/bin/python3
|
1
2
3
4
5
6
7
8
9
|
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if
[
-
f ~
/
.bashrc ]; then
. ~
/
.bashrc
fi
# User specific environment and startup programs
PATH
=
$PATH:$HOME
/
bin
:
/
usr
/
local
/P
ython3
/
bin
export PATH
|
按ESC,輸入:wq,按回車保存退出編輯。
修改完記得執行行下面的命令,讓上一步的修改生效:
1
|
# source ~/.bash_profile
|
檢查Python3及pip3是否正常可用:
1
2
3
4
|
# python3 -V
Python
3.6
.5
# pip3 -V
pip
9.0
.3
from
/
usr
/
local
/P
ython3
/
lib
/
python3.
6
/
site
-
packages (python
3.6
)
|