wget
解壓檔案
[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編輯器
[root@localhost python-2.7.4]# yum install gcc
..略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變更後的名字)
Linux更改將Python環境預設
步驟 刪除原來指向python2的軟鏈結 sudo mv usr bin python usr bin python.bak usr local python3.6 bin python3.6 這個路徑為實際的python3.6的bin資料夾下的python3.6的路徑,這個按照自己的實際情況進行更...
linux將python3設為預設
但是預設的python命令是python2,我要想執行python3就必須輸入python3。為解決如何將python3設為預設的問題,可以採用以下方式 直接執行這兩個命令即可 sudo update alternatives install usr bin python python usr bi...
將linux預設python公升級到2 7 4版本
wget 解壓檔案 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 gramm...