將linux預設python升級到2.7.4版本

來源:互聯網
上載者:User

標籤:

第一步:下載python2.7.4版本源碼:

wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz

解壓檔案

[[email protected] ~]$ tar jxvf Python-2.7.4.tar.bz2

[[email protected] ~]$ cd Python-2.7.4
[[email protected] Python-2.7.4]$ ls
config.guess configure    Demo  Grammar install-sh  LICENSE Makefile.pre.in  Modules Parser PCbuild       Python RISCOS   Tools
config.sub   configure.ac Doc   Include Lib        Mac     Misc            Objects PC     pyconfig.h.in  README setup.py
[[email protected] Python-2.7.4]$ su -
口令:
[[email protected] ~]# mkdir /usr/local/python2.7.4
[[email protected] ~]# cd /home/
[[email protected] home]# cd niuxl/Python-2.7.4
[[email protected] Python-2.7.4]# ls
config.guess configure    Demo  Grammar install-sh  LICENSE Makefile.pre.in  Modules Parser PCbuild       Python RISCOS   Tools
config.sub   configure.ac Doc   Include Lib        Mac     Misc            Objects PC     pyconfig.h.in  README setup.py    

編譯之前,需要先安裝zlib包:

[[email protected] Python-2.7.4]# yum install zlib zlib-devel
[[email protected] Python-2.7.4]# ./configure--prefix=/usr/local/python2.7.4
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/niuxl/Python-2.7.4‘:
configure: error: no acceptable C compiler found in $PATH

缺少c編輯器

安裝c編輯器:

[[email protected] Python-2.7.4]# yum install gcc

..略

註:有一個選擇y和n的地方,提示是否繼續下載,輸入y,斷行符號即可!

gcc安裝完成

繼續編譯python

[[email protected] Python-2.7.4]# ./configure--prefix=/usr/local/python2.7.4

..(略)

ok編譯成功

[[email protected] Python-2.7.4]# make&& make install

安裝成功

 

[[email protected] Python-2.7.4]# python -V
Python 2.4.3

目前版本依然是2.4.3,現在開始升級python,

查看python命令所在目錄

[[email protected] Python-2.7.4]# whereis python
python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4/usr/include/python2.4 /usr/share/man/man1/python.1.gz

將/usr/bin/python 的軟串連修改為python2.4.3

[[email protected] Python-2.7.4]# mv /usr/bin/python/usr/bin/python2.4.3

[[email protected] Python-2.7.4]# python
-bash: /usr/bin/python: 沒有那個檔案或目錄

python命令找不到,這時只需要將版本python2.7.4命令加入環境變數即可!

方式1:

修改/etc/profile加入如下兩行:

PATH=$PATH:/usr/local/python2.7.4/bin
export PATH

然後

[[email protected] Python-2.7.4]# source /etc/profile

[[email protected] Python-2.7.4]# python -V
Python 2.7.4

當然也可以建立2.7.4版本的python的軟串連:/usr/bin/python

[[email protected] ~]# ln -s /usr/local/python2.7.4/bin/python/usr/bin/python

亦可

ok,python升級完成

到現在為止,還有最後一件事需要做,那就是yum與python的相容問題:

[[email protected] pipe]# vi /usr/bin/yum

#!/usr/bin/python

第一行修改為

#!/usr/bin/python2.4.3(即原始的python變更後的名字)

將linux預設python升級到2.7.4版本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.