1. 程式人生 > >Linux環境下安裝python3

Linux環境下安裝python3

its 路徑 hat port mar color out -c default

Linux環境下已存在python2,不要去卸載系統中已經存在的python2,否則會造成系統中好多其他需要python執行的程序異常

查看python2的安裝路徑: which python2

查看python3的安裝路徑:which python3

Python3安裝方法:

首先切換到你想下載的路徑下,在執行以下命令

[test@~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

[test@~]# tar -zxf Python-3.6.5.tgz

[test@~]# cd Python-3.6.5

在安裝包中有一個README的文件,裏面有寫如何安裝

[test@localhost Python-3.6.5]# ls

[test@localhost Python-3.6.5]# ./configure

[test@localhost Python-3.6.5]# make

[test@localhost Python-3.6.5]# make test

[test@localhost Python-3.6.5]# make install

安裝好了,然後打開python3.6

[test@localhost Python-3.5.2]# python3
Python 3.6.5 (default, Mar 25 2018, 13:46:07)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Linux下 ./configure、make 、make test/make check、sudo make install 的作用

  • config/configure/Configure
    • 這個是用來檢測你的安裝平臺的目標特征的。比如它會檢測你是不是有CC或GCC,並不是需要CC或GCC,它是個shell腳本
    • 這一步一般用來生成 Makefile,為下一步的編譯做準備,你可以通過在 configure 後加上參數來對安裝進行控制,比如:
      • ./configure --prefix=/usr
      • 上面的意思是將該軟件安裝在 /usr 下面
      • 執行文件就會安裝在 /usr/bin (而不是默認的 /usr/local/bin)
      • 資源文件就會安裝在 /usr/share(而不是默認的/usr/local/share)
      • 同時一些軟件的配置文件你可以通過指定 --sys-config= 參數進行設定
      • 還有諸如:--with、--enable、--without、--disable 等等參數對編譯加以控制,你可以通過 ./configure --help 察看詳細的說明幫助
  • make
    • 這一步是用來編譯的,它從Makefile中讀取指令,然後編譯
    • 這一步就是編譯,大多數的源代碼包都經過這一步進行編譯
    • 當然有些perl或python編寫的軟件需要調用perl或python來進行編譯
    • 如果 在 make 過程中出現 error ,你就要記下錯誤代碼(註意不僅僅是最後一行),然後你可以向開發者提交 bugreport(一般在 INSTALL 裏有提交地址),或者你的系統少了一些依賴庫等,這些需要自己仔細研究錯誤代碼
  • make test / make check
    • 顧名思義,這一步就是對上一步 make 的檢查了,要確保 make 是沒有錯誤的,也就是這一步的 test、check要全部是 OK 的,error 為0
  • sudo make install
    • 這一步是用來安裝的,它也從Makefile中讀取指令,安裝到指定的位置
    • 這條命令來進行安裝,一般需要你有 root 權限(因為要向系統寫入文件),所以前面用了 sudo

Linux環境下安裝python3