CentOS7系统默认安装了python2.7
$ python --versionPython 2.7.5
怎么安装python3?
下载python3安装包
$ 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 用时 21s2018-11-27 15:16:45 (1.02 MB/s) - 已保存 “Python-3.6.3.tgz” [22673115/22673115])
$ lsPython-3.6.3.tgz$ tar -xvf Python-3.6.3.tgz$ lsPython-3.6.3 Python-3.6.3.tgz$ cd Python-3.6.3$ lsaclocal.m4 config.sub configure.ac Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild pyconfig.h.in README.rst Toolsconfig.guess configure Doc Include Lib Mac Misc Objects PC Programs Python setup.py
执行配置
$ ./configure
执行编译
make
执行安装
make install
如果需要安装失败的提示:
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, inensurepip._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 pipzipimport.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
至此,安装完成。查看python3版本
$ python3 --versionPython 3.6.3