升級python

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

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

解壓文件

[aa@localhost ~]$ tar jxvf Python-2.7.4.tar.bz2

[niuxl@localhost ~]$ cd Python-2.7.4
[niuxl@localhost 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
[niuxl@localhost Python-2.7.4]$ su -
口令:
[root@localhost ~]# mkdir /usr/local/python2.7.4
[root@localhost ~]# cd /home/
[root@localhost home]# cd niuxl/Python-2.7.4
[root@localhost 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包:

[root@localhost Python-2.7.4]# yum install zlib zlib-devel
[root@localhost 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編輯器:

[root@localhost Python-2.7.4]# yum install gcc

..略

注:有一個選擇y和n的地方,提示是否繼續下載,輸入y,回車即可!

gcc安裝完成

繼續編譯python

[root@localhost Python-2.7.4]# ./configure --prefix=/usr/local/python2.7.4

..(略)

ok編譯成功

[root@localhost Python-2.7.4]# make && make install

安裝成功

 

[root@localhost Python-2.7.4]# python -V
Python 2.4.3

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

查看python命令所在目錄

[root@localhost 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

[root@localhost Python-2.7.4]# mv /usr/bin/python /usr/bin/python2.4.3

[root@localhost 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

然後

[root@localhost Python-2.7.4]# source /etc/profile

[root@localhost Python-2.7.4]# python -V
Python 2.7.4

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

[root@localhost ~]# ln -s /usr/local/python2.7.4/bin/python /usr/bin/python

亦可

ok,python升級完成

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

[root@localhost pipe]# vi /usr/bin/yum

#!/usr/bin/python

第一行修改爲

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章