前一段時間準備安裝最新版本Python(Python3.6)。結果安裝時各類錯誤,如今從新安裝。 下載源代碼壓縮包。python
[root@localhost ~]# wget https://www.python.org/ftp/python/3.5.3/Python-3.5.3.tar.xz
安裝python3依賴軟件。linux
[root@localhost ~]# yum -y groupinstall development [root@localhost ~]# yum -y install zlib-devel
解壓源代碼文件並安裝。bash
[root@localhost ~]# tar -xvf Python-3.5.3.tar.xz #配置 [root@localhost Python-3.5.3]# ./configure #擴展配置 [root@localhost Python-3.5.3]# ./configure --enable-optimizations #請自行查看兩種配置方式不一樣點 #編譯和安裝 [root@localhost Python-3.5.3]make [root@localhost Python-3.5.3]make install #安裝失敗請執行該命令 [root@localhost Python-3.5.3]# make distclean
編譯與安裝過程根據機器配置,可能須要幾分鐘到幾十分鐘不等,請耐心等待安裝完成。架構
也能夠合併執行安裝命令(編譯完成後直接安裝)。python2.7
[root@localhost Python-3.5.3]make & make altinstall
將安裝目錄添加到系統環境變量。假設默認安裝路徑是/usr/local/bin。編輯器
export PATH="/usr/local/bin:$PATH"
查看Python安裝路徑。this
[root@localhost ~]# which python /usr/bin/python [root@localhost ~]# whereis python python: /usr/bin/python /usr/bin/python2.7 /usr/bin/python2.7-config /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/local/bin/python3.5m /usr/local/bin/python3.5 /usr/local/bin/python3.5m-config /usr/local/bin/python3.5-config /usr/local/lib/python3.5 /usr/include/python2.7 /usr/share/man/man1/python.1.gz [root@localhost ~]#
CentOS 7預裝Python2,使用Python3請先執行命令。推薦同時建立pip3連接。插件
ln -s /usr/local/bin/python3.5 /bin/python3
完成後便可正常使用python和python3命令。code
[root@localhost ~]# python Python 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> exit() #Python3 [root@localhost ~]# python3 Python 3.5.3 (default, Mar 22 2017, 10:23:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
下面介紹安裝Python默認IDE(Python IDLE)。orm
如下是本機安裝過程。
[root@localhost ~]# yum install python-tools.x86_64 已加載插件:fastestmirror, langpacks base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解決依賴關係 --> 正在檢查事務 ---> 軟件包 python-tools.x86_64.0.2.7.5-48.el7 將被 安裝 --> 正在處理依賴關係 tkinter = 2.7.5-48.el7,它被軟件包 python-tools-2.7.5-48.el7.x86_64 須要 --> 正在檢查事務 ---> 軟件包 tkinter.x86_64.0.2.7.5-48.el7 將被 安裝 --> 正在處理依賴關係 libtk8.5.so()(64bit),它被軟件包 tkinter-2.7.5-48.el7.x86_64 須要 --> 正在處理依賴關係 libtcl8.5.so()(64bit),它被軟件包 tkinter-2.7.5-48.el7.x86_64 須要 --> 正在處理依賴關係 libTix.so()(64bit),它被軟件包 tkinter-2.7.5-48.el7.x86_64 須要 --> 正在檢查事務 ---> 軟件包 tcl.x86_64.1.8.5.13-8.el7 將被 安裝 ---> 軟件包 tix.x86_64.1.8.4.3-12.el7 將被 安裝 ---> 軟件包 tk.x86_64.1.8.5.13-6.el7 將被 安裝 --> 解決依賴關係完成 依賴關係解決 =============================================================================================================== Package 架構 版本 源 大小 =============================================================================================================== 正在安裝: python-tools x86_64 2.7.5-48.el7 base 852 k 爲依賴而安裝: tcl x86_64 1:8.5.13-8.el7 base 1.9 M tix x86_64 1:8.4.3-12.el7 base 254 k tk x86_64 1:8.5.13-6.el7 base 1.4 M tkinter x86_64 2.7.5-48.el7 base 322 k 事務概要 =============================================================================================================== 安裝 1 軟件包 (+4 依賴軟件包) 總下載量:4.7 M 安裝大小:13 M Is this ok [y/d/N]: y Downloading packages: (1/5): tkinter-2.7.5-48.el7.x86_64.rpm | 322 kB 00:00:00 (3/5): tcl-8.5.13-8.el7.x86_64.rpm 18% [=====- ] 0.0 B/s | 887 kB --:--:-- ETA (2/5): python-tools-2.7.5-48.el7.x86_64.rpm | 852 kB 00:00:00 (3/5): tcl-8.5.13-8.el7.x86_64.rpm | 1.9 MB 00:00:00 (4/5): tix-8.4.3-12.el7.x86_64.rpm | 254 kB 00:00:00 (5/5): tk-8.5.13-6.el7.x86_64.rpm 86% [==========================- ] 3.1 MB/s | 4.1 MB 00:00:00 ETA (5/5): tk-8.5.13-6.el7.x86_64.rpm 98% [==============================-] 2.9 MB/s | 4.6 MB 00:00:00 ETA (5/5): tk-8.5.13-6.el7.x86_64.rpm | 1.4 MB 00:00:01 --------------------------------------------------------------------------------------------------------------- 總計 2.8 MB/s | 4.7 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : 1:tcl-8.5.13-8.el7.x86_64 1/5 正在安裝 : 1:tk-8.5.13-6.el7.x86_64 2/5 正在安裝 : 1:tix-8.4.3-12.el7.x86_64 3/5 正在安裝 : tkinter-2.7.5-48.el7.x86_64 4/5 正在安裝 : python-tools-2.7.5-48.el7.x86_64 5/5 驗證中 : 1:tix-8.4.3-12.el7.x86_64 1/5 驗證中 : python-tools-2.7.5-48.el7.x86_64 2/5 驗證中 : 1:tcl-8.5.13-8.el7.x86_64 3/5 驗證中 : tkinter-2.7.5-48.el7.x86_64 4/5 驗證中 : 1:tk-8.5.13-6.el7.x86_64 5/5 已安裝: python-tools.x86_64 0:2.7.5-48.el7 做爲依賴被安裝: tcl.x86_64 1:8.5.13-8.el7 tix.x86_64 1:8.4.3-12.el7 tk.x86_64 1:8.5.13-6.el7 tkinter.x86_64 0:2.7.5-48.el7 完畢! [root@localhost ~]#
打開IDLE。
[root@localhost ~]idle
這裏我推薦編輯器有Anaconda和Spyder。
先說Anaconda安裝過程。
#對應Python3.6 [root@localhost Python-3.5.3]https://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86_64.sh [root@localhost Python-3.5.3]https://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86.sh #安裝 [root@localhost Python-3.5.3]bash Anaconda3-4.3.1-Linux-x86_64.sh