centos 系统自带python2.7解释器
下载源码包
进入python官网选择 Downloads Source code (下载源代码)


选择Gzip开头的源码包下载

开始安装
1.在 CentOS 7 中安装 Python3 之前,请确保系统中已经有了所有必要的开发依赖:
yum -y install zlib-devel
2.把源码包上传到服务器后,解压:
tar xf Python-3.6.2.tgz

3.编译和安装
cd Python-3.6.2
./configure && make && make install

报错
在make阶段报错
zipimport.ZipImportError: can't decompress data; zlib not available make: *** [install] 错误 1
原因:因为缺少zlib 的相关工具包导致
解决办法:
yum -y install zlib*
重新执行
make
继续安装即可
验证
centos下默认已经安装python2.7版本
输入python 会进入python-2.x版本
输入python3 会进入python-3.x版本
退出python模式:
按键: Ctrl+D
或者输入: exit()

至此centos环境下的python3环境已经搭建好
其他Linux版本安装python3步骤基本相同
网友评论