1. 程式人生 > >騰訊雲CentOS安裝Python3.6

騰訊雲CentOS安裝Python3.6

由於剛搭建的騰訊雲伺服器上預設只有Python2.7,本文旨在記錄Python3.6的安裝過程,以便日後檢視。

1 檢視python版本和依賴關係

// 切換目錄
cd /usr/bin/

// 檢視python檔案
ls python*      // output: python python2 python2.7

// 檢視依賴關係
ls -al python*  // output: 發現python預設指向python2,python2指向python2.7

這裡寫圖片描述

2 下載原始碼並解壓

// 建立並切換目錄
mkdir /usr/local/python3
cd /usr/local/python3

// 下載原始碼壓縮檔案
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz // 解壓並檢視當前目錄 tar -xvf Python-3.6.3.tgz ll // output: 生成名為Python-3.6.3的目錄

3 編譯

  • configure & make
// 切換目錄
cd Python-3.6.3

// 建立編譯規則
./configure --prefix=/usr/local/python3Dir

// 編譯
make
make install
  • 編譯報錯
// 編譯期間報如下錯誤
// checking build system type... x86_64-pc-linux-gnu
//
checking host system type... x86_64-pc-linux-gnu // checking for python3.6... no // checking for python3... no // checking for python... python // checking for --enable-universalsdk... no // checking for --with-universal-archs... no // checking MACHDEP... linux // checking for --without-gcc... no // checking for --with
-icc... no // checking for gcc... no // checking for cc... no // checking for cl.exe... no // configure: error: in '/root/Python-3.6.4': // configure: error: no acceptable C compiler found in $PATH // See 'config.log' for more details // 需安裝gcc yum -y install gcc

4 檢查是否安裝成功

// 檢查版本
python3 -V      // output: Python3.6.3
// 檢查依賴關係
cd /usr/local/bin/
ls -al python*

這裡寫圖片描述

  • 至此成功安裝python3,但是預設python和pip指令仍然指向python2版本,因此使用python3pip3時必須顯式指定其版本。若需更改預設版本,可參考文末連線。

參考資料