Centos7默认自带Python2.7,可安装Python3与Python2共存。
[root@Python ~]# python -V
Python 2.7.5
1.安装编译相关工具
[root@Python ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@Python ~]# yum -y groupinstall "Development tools"
[root@Python ~]# 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
[root@Python ~]# yum install wget libffi-devel -y
2.下载安装包并解压
[root@Python ~]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
[root@Python ~]# tar -xvJf Python-3.7.0.tar.xz
3.编译安装
[root@Python ~]# mkdir /usr/local/python3
[root@Python ~]# cd Python-3.7.0
[root@Python ~]# ./configure --prefix=/usr/local/python3
...
[root@Python ~]# make && make install
...
4.设置环境变量
[root@syztoo ~]# sed -i '/export PATH=$PATH/s/$/:\/usr\/local\/python3\/bin/' /etc/profile
[root@syztoo ~]# source /etc/profile
5.验证安装情况
[root@docker Python-3.7.0]# python3 -V
Python 3.7.0
[root@docker Python-3.7.0]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)