CentOS7系統默認安裝了python2.7html
$ python --version Python 2.7.5
怎麼安裝python3?python
$ wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz --2018-11-27 15:16:23-- https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz 正在解析主機 www.python.org (www.python.org)... 151.101.108.223, 2a04:4e42:1a::223 正在鏈接 www.python.org (www.python.org)|151.101.108.223|:443... 已鏈接。 已發出 HTTP 請求,正在等待迴應... 200 OK 長度:22673115 (22M) [application/octet-stream] 正在保存至: 「Python-3.6.3.tgz」 100%[====================================================================================================================================>] 22,673,115 3.94MB/s 用時 21s 2018-11-27 15:16:45 (1.02 MB/s) - 已保存 「Python-3.6.3.tgz」 [22673115/22673115])
$ ls Python-3.6.3.tgz $ tar -xvf Python-3.6.3.tgz $ ls Python-3.6.3 Python-3.6.3.tgz $ cd Python-3.6.3 $ ls aclocal.m4 config.sub configure.ac Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild pyconfig.h.in README.rst Tools config.guess configure Doc Include Lib Mac Misc Objects PC Programs Python setup.py
執行配置sql
$ ./configure
執行編譯bootstrap
make
執行安裝app
make install
若是須要安裝失敗的提示:python2.7
Traceback (most recent call last): File "/root/downloads/Python-3.6.3/Lib/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/root/downloads/Python-3.6.3/Lib/runpy.py", line 85, in _run_code exec(code, run_globals) File "/root/downloads/Python-3.6.3/Lib/ensurepip/__main__.py", line 4, in <module> ensurepip._main() File "/root/downloads/Python-3.6.3/Lib/ensurepip/__init__.py", line 189, in _main default_pip=args.default_pip, File "/root/downloads/Python-3.6.3/Lib/ensurepip/__init__.py", line 102, in bootstrap _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) File "/root/downloads/Python-3.6.3/Lib/ensurepip/__init__.py", line 27, in _run_pip import pip zipimport.ZipImportError: can't decompress data; zlib not available
須要安裝Development tools
和zlib
相關工具工具
$ yum groupinstall "Development tools" $ yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-develtk-devel gdbm-devel db4-devel libpcap-devel xz-devel
執行完後再執行安裝make install
ui
至此,安裝完成。查看python3版本code
$ python3 --version Python 3.6.3