溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

python2.6.6升級到python2.7.14的案例

發(fā)布時間:2021-02-18 10:51:53 來源:億速云 閱讀:149 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹python2.6.6升級到python2.7.14的案例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

其實網(wǎng)上有很多關(guān)于python2.6.6 升級到python2.7的文章,但是我對比這些類似的文章升級之后,發(fā)現(xiàn)其中有錯誤的地方,于是決定還是自己寫一個真正的升級過程。

我的虛擬機里安裝的是CentOS 6.5里面默認安裝的Python2.6.6,因為要學習TensorFlow,所以決定升級到2.7

1、下載安裝包

其實在python官網(wǎng)上有個目錄列舉出了各個版本的下載安裝包,點擊這里,可以看到

python2.6.6升級到python2.7.14的案例

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

python2.6.6升級到python2.7.14的案例

點擊這里的Python-2.7.14.tgz可以直接下載安裝包文件,也可以使用wget來直接下載,如果需要安裝的服務(wù)器無法直接訪問外網(wǎng),可以使用下載安裝包文件的方式,如果可以訪問外部推薦使用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

執(zhí)行之后提示是這樣

[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

執(zhí)行yum -y install gcc安裝了gcc ,重新執(zhí)行./configure --prefix=/usr/local/python2.7可以正常安裝python

執(zhí)行make

執(zhí)行make install

然后進入/usr/local/python2.7/bin,這個目錄的內(nèi)容如下:

[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]#

3、測試

在這個目錄下執(zhí)行python2或者python2.7都可以出現(xiàn)python的提示符表示安裝成功

python2.6.6升級到python2.7.14的案例

4、建立軟連接

1)備份python2.6.6的啟動文件

mv /usr/bin/python /usr/bin/python2.6.6

2)創(chuàng)建用于啟動python2.7.14的軟連接

ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python,有的文章里寫的是下面這樣:ln -s /usr/local/bin/python2.7 /usr/bin/python ,事實證明是有錯誤的。因為編譯好的python2.7.14可執(zhí)行文件在/usr/local/python2.7/bin/這個目錄下面并不在/usr/local/python2.7目錄下,同時創(chuàng)建符號鏈接也需要指定具體的可執(zhí)行文件名才行。

5.測試

下面我們測試下創(chuàng)建好的軟連接

python2.6.6升級到python2.7.14的案例

如果軟鏈接的->后面是紅色顯示的字體,通常表示這個軟連接指向的路徑是無效的。

此時我們換個其他的目錄,比如在/下面執(zhí)行下python,

python2.6.6升級到python2.7.14的案例

可以看到提示的Python2.7.14,證明安裝成功,但是還沒有徹底結(jié)束

6. 配置yum啟動路徑

yum不兼容 Python 2.7,但是我們現(xiàn)在已經(jīng)把Python2.6.6升級成了Python2.7.14, 所以yum不能正常工作,我們需要指定 yum 的Python版本:

vim /usr/bin/yum

將頭部#!/usr/bin/python 改成#!/usr/bin/python2.6.6(剛剛備份的)

python2.6.6升級到python2.7.14的案例

然后保存退出即可。

如果我們想要啟動老版本python2.6.6,可以執(zhí)行python2.6.6即可,如果是想啟動python2.7,只需要執(zhí)行python即可

因此這里的升級不是把python2.6.6徹底干掉,而是重新安裝了python2.7.14.而且也兼顧到y(tǒng)um的使用。

以上是“python2.6.6升級到python2.7.14的案例”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI