环境说明centos: 7.4
目前python: 2.7.5
# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
# python
Python 2.7.5 (default, Aug 4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
依赖安装
安装开发工具包
# sudo yum -y groupinstall "Development tools"
安装python3-7-0需要的依赖包
# sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
源码准备
下载python-3.7.0的源码压缩包
# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
解压,python源码有两种压缩包:
xxx.tgz: 对应解压方式为:tar -zxvf xxx.tgz
xxx.tar.xz: 对应解压方式为:tar -Jxvf xxx.tar.xz
源码安装
源码的安装分三步:配置、编译、安装
配置
进入解压后的目录进行配置
# ./configure --prefix=/usr/local/python3 //安装完成后python3.7的执行文件在/usr/local/python3/bin编译
# make安装
# make install
设置环境变量
vim .bash_profile
PYTHON37=/usr/local/python3/bin
# 在PATH后面添加:$PYTHON37
PATH=$PATH:$PYTHON37
export PATH
使环境变量生效
# source .bash_profile
接下来你就可以通过python3使用python3.7了。
注意:
1. 安装python3时会安装pip3,也在`/usr/local/python3/bin`目录下
2. Centos 默认有python2.7,通过键入python 能开启python2,键入python3能打开python3的解释器
参考链接
长按二维码关注我们