python linux 安裝

參考文件地址

http://ericslau.iteye.com/blog/1845654

下載安裝包

 可利用linux自帶下載工具wget下載,如下所示: 
    1 # wget http://www.python.org/ftp/python/3.3.0/Python-3.3.0.tgz 
     2   tar -xzvf Python-3.3.0.tgz) 
進入壓縮目錄後在執行以下命令
  1 cd Python-3.3.0
    在編譯前先在/usr/local建一個文件夾python3(作爲python的安裝路徑,以免覆蓋老的版本) 
  1 mkdir /usr/local/python3 ,一定要進入解壓後得目錄,裏面纔會有configure 該文件

開始編譯安裝 
1 ./configure --prefix=/usr/local/python3  執行該命令後創建makefile文件

  2 make 

 3 make install 

注意

 

  在執行./configure --prefix=/usr/local/python3 ,時出現 

 

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking for --enable-universalsdk... no

checking for --with-universal-archs... 32-bit

checking MACHDEP... linux

checking for --without-gcc... no

checking for gcc... no

checking for cc... no

checking for cl.exe... no

configure: error: in `/usr/local/Python/Python-3.3.0':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

執行yum -y install gcc 後在安裝執行上述命令即可


   此時沒有覆蓋老版本,再將原來/usr/bin/python鏈接改爲別的名字 
1 mv /usr/bin/python /usr/bin/python_old 

  再建立新版本python的鏈接 
1 ln -s /usr/local/python3/bin/python3 /usr/bin/python 

 

  這個時候輸入 
1 python 

  就會顯示出python的新版本信息 
1 Python 3.1.2 (r312:79147, Oct 21 2012, 01:03:21)) 
2 [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 
3 Type "help", "copyright", "credits" or "license" for more information. 
4 >>> 

  PS:如果不建立新安裝路徑python3,而是直接默認安裝,則安裝後的新python應該會覆蓋linux下自帶的老版本,也有可能不覆蓋,具體看安裝過程了,這個大家可以自己試驗下,當然如果還想保留原來的版本,那麼這種方法最好不過了。 

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