[root@template ~]# python -v # /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6/encodings/utf_8.py import encodings.utf_8 # precompiled from /usr/lib64/python2.6/encodings/utf_8.pyc Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "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 總用量 20108 drwxrwxr-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/python3 make && make installchecking 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... no checking MACHDEP... linux 中間步驟省略............ checking for --without-gcc... no configure: creating ./config.status config.status: creating Makefile.pre config.status: creating Modules/Setup.config config.status: creating Misc/python.pc config.status: creating Misc/python-config.sh config.status: creating Modules/ld_so_aix config.status: creating pyconfig.h creating Modules/Setup creating Modules/Setup.local creating 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) \ fi rm -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=/ ; \ fi Ignoring 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]# python Python 3.5.2 (default, Aug 2 2016, 11:35:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() #<----退出python PS:如果不建立新安裝路徑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 --version Python 3.5.2