其實網上有很多關于python2.6.6 升級到python2.7的文章,但是我對比這些類似的文章升級之后,發現其中有錯誤的地方,于是決定還是自己寫一個真正的升級過程。
我的虛擬機里安裝的是CentOS 6.5里面默認安裝的Python2.6.6,因為要學習TensorFlow,所以決定升級到2.7
1、下載安裝包
其實在python官網上有個目錄列舉出了各個版本的下載安裝包,點擊這里,可以看到

這里是按照發布時間排列的,往下拉可以找到已經發布的各個版本,我們找到2.7.14,這個是比較重要的一個版本

點擊這里的Python-2.7.14.tgz可以直接下載安裝包文件,也可以使用wget來直接下載,如果需要安裝的服務器無法直接訪問外網,可以使用下載安裝包文件的方式,如果可以訪問外部推薦使用wget方式。
wget https://www.python.org/ftp/python/Python-2.7.14.tgz
無論用哪種方式,下載到安裝包之后都會得到Python-2.7.14.tgz這個安裝文件
2、解壓配置
解壓安裝文件
tar -zvf Python-2.7.14.tgz
得到 Python-2.7.14文件夾
cd Python-2.7.14
./configure --prefix=/usr/local/python2.7
執行之后提示是這樣
[root@node2 Python-2.7.14]# ./configure --prefix=/usr/local/python2.7 checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python2.7... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... 32-bit checking MACHDEP... linux2 checking EXTRAPLATDIR... 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 `/opt/package/python_lib/Python-2.7.14': configure: error: no acceptable C compiler found in $PATH See `config.log' for more details
提示:no acceptable C compiler found in $PATH
于是趕緊測試下gcc果然這個不存在,可能是虛擬機在安裝CentsOS時沒有選擇安裝GCC
[root@node2 Python-2.7.14]# gcc -bash: gcc: command not found [root@node2 Python-2.7.14]# yum -y install gcc
執行yum -y install gcc安裝了gcc ,重新執行./configure --prefix=/usr/local/python2.7可以正常安裝python
執行make
執行make install
然后進入/usr/local/python2.7/bin,這個目錄的內容如下:
[root@node2 bin]# ll 總用量 6164 -rwxr-xr-x. 1 root root 111 11月 9 19:24 2to3 -rwxr-xr-x. 1 root root 109 11月 9 19:24 idle -rwxr-xr-x. 1 root root 94 11月 9 19:24 pydoc lrwxrwxrwx. 1 root root 7 11月 9 19:27 python -> python2 lrwxrwxrwx. 1 root root 9 11月 9 19:27 python2 -> python2.7 -rwxr-xr-x. 1 root root 6273995 11月 9 19:24 python2.7 -rwxr-xr-x. 1 root root 1697 11月 9 19:27 python2.7-config lrwxrwxrwx. 1 root root 16 11月 9 19:27 python2-config -> python2.7-config lrwxrwxrwx. 1 root root 14 11月 9 19:27 python-config -> python2-config -rwxr-xr-x. 1 root root 18557 11月 9 19:24 smtpd.py [root@node2 bin]#
新聞熱點
疑難解答