Day1-Centos6.6下python升級python3.5.2步驟,centos升級python3.5
[root@template ~]# python -v# /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6/encodings/utf_8.pyimport encodings.utf_8 # precompiled from /usr/lib64/python2.6/encodings/utf_8.pycPython 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2);import readline # dynamically loaded from /usr/lib64/python2.6/lib-dynload/readline.so>>> exit()
Python3.5.2官方網站
https://www.python.org/downloads/source/
升級為python3.5版本步驟
root@template ~]# cd /home/nulige/tools/#下載python-3.5.2[root@template tools]# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz[root@template tools]# ll總用量 20104-rw-r--r-- 1 root root 20566643 6月 26 05:47 Python-3.5.2.tgz#解壓到下載目錄[root@template tools]# tar zxvf Python-3.5.2.tgz [root@template tools]# ll總用量 20108drwxrwxr-x 16 1000 1000 4096 6月 26 05:38 Python-3.5.2-rw-r--r-- 1 root root 20566643 6月 26 05:47 Python-3.5.2.tgz-rwxrwxrwx. 1 root root 13259 5月 8 16:10 system_optimize_scripts.sh#進入解壓後的檔案夾[root@template tools]# cd Python-3.5.2#在編譯前先在/usr/local建一個檔案夾python3(作為python的安裝路徑,以免覆蓋老的版本)[root@template Python-3.5.2]# mkdir /usr/local/python3#開始編譯安裝[root@template Python-3.5.2]# ./configure --prefix=/usr/local/python3make && make installchecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking for --enable-universalsdk... nochecking for --with-universal-archs... nochecking MACHDEP... linux中間步驟省略............checking for --without-gcc... noconfigure: creating ./config.statusconfig.status: creating Makefile.preconfig.status: creating Modules/Setup.configconfig.status: creating Misc/python.pcconfig.status: creating Misc/python-config.shconfig.status: creating Modules/ld_so_aixconfig.status: creating pyconfig.hcreating Modules/Setupcreating Modules/Setup.localcreating Makefile[root@template Python-3.5.2]# make && make install中間步驟省略............if test "x" != "x" ; then \ rm -f /usr/local/python3/bin/python3-32; \ (cd /usr/local/python3/bin; ln -s python3.5-32 python3-32) \ firm -f /usr/local/python3/share/man/man1/python3.1(cd /usr/local/python3/share/man/man1; ln -s python3.5.1 python3.1)if test "xupgrade" != "xno" ; then \ case upgrade in \ upgrade) ensurepip="--upgrade" ;; \ install|*) ensurepip="" ;; \ esac; \ ./python -E -m ensurepip \ $ensurepip --root=/ ; \ fiIgnoring ensurepip failure: pip 8.1.1 requires SSL/TLS[root@template Python-3.5.2]# echo $?0編譯完成#################################################此時沒有覆蓋老版本,再將原來/usr/bin/python連結改為別的名字[root@template Python-3.5.2]# mv /usr/bin/python /usr/bin/python_old#再建立新版本python的軟連結[root@template Python-3.5.2]# ln -s /usr/local/python3/bin/python3 /usr/bin/python#就會顯示出python的新版本資訊[root@template Python-3.5.2]# pythonPython 3.5.2 (default, Aug 2 2016, 11:35:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> exit() #<----退出pythonPS:如果不建立新安裝路徑python3,而是直接預設安裝,則安裝後的新python應該會覆蓋linux下內建的老版本,也有可能不覆蓋,具體看安裝過程了,這個大家可以自己實驗下,當然如果還想保留原來的版本,那麼這種方法最好不過了。注意事項:這種方法雖然能安裝成功,但會導致yum不能正常使用。解決方案:[root@template tools]# cp /usr/bin/yum /usr/bin/yum.backup_2016-08-02修改第一行參數vi /usr/bin/yum 把 #!/usr/bin/python 修改為:/usr/bin/python_old 或把 #!/usr/bin/python 修改為:/usr/bin/python2.6#查看版本[root@template Python-3.5.2]# python --versionPython 3.5.2