## Python 2.7.6升級到版本升級3.5
#### 查看 Python 版本號
python -V (大V)
#### 下載新版本
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
注意 ,這里可以選擇目錄,默認是你當前的目錄
#### 下載完成之后,進行解壓縮:
```
? ?tar -zxvf Python-3.5.2.tgz
```
#### 進入解壓縮后的目錄,安裝配置:
```
cd Python-3.5.2/
```
#### configure 安裝
```
?./configure?
```
#### 執行 ./configure 時,如果報錯:
```
? configure: error: no acceptable C compiler found in $PATH
? ? 說明沒有安裝合適的編譯器。這時,需要安裝/升級 gcc 及其它依賴包。
yum install make gcc gcc-c++?
完成之后,重新執行:
? ./configure?
```
#### 編譯 & 安裝
```
配置完成之后,就可以編譯了:
make
```
漫長的等待……完成后,安裝:
```
? ? ? ? make install
```
#### 驗證
安裝成功以后,就可以查看 Python 的版本了:
```
# python -V
? ? ? ? Python 2.7.5
? ? ? ? # python3 -V
? ? ? ? Python 3.5.2
```
**注意:**在 /usr/local/bin/ 下有一個 python3 的鏈接,指向 bin 目錄下的 python 3.5。
#### 設置 3.x 為默認版本
> 查看 Python 的路徑,在 /usr/bin 下面。可以看到 python 鏈接的是 python 2.7,所以,執行 python 就相當于執行 python 2.7。
>
#### 將原來 python 的軟鏈接重命名:
* mv /usr/bin/python /usr/bin/python.bak
#### 將 python 鏈接至 python3:
* ln -s /usr/local/bin/python3 /usr/bin/python
#### 這時,再查看 Python 的版本:
```
? # python -V
? ? ? ? Python 3.5.2
```
#### 配置 yum
> 升級 Python 之后,由于將默認的 python 指向了 python3,yum 不能正常使用,需要編輯 yum 的配置文件:
```
# vi /usr/bin/yum
```
同時修改:
```
# vi /usr/libexec/urlgrabber-ext-down
```
> 將兩個文件中的 #!/usr/bin/python 改為 #!/usr/bin/python2.7,保存退出即可。