1、先查看当前系统中的python版本
[root@master ~]# python
Python 2.7.5(default, Aug 42017,00:39:18)[GCC4.8.520150623(Red Hat 4.8.5-16)] on linux2
Type "help","copyright","credits" or "license"for more information.>>>exit() #退出
2、 安装依赖包
导入Python-3.7.0.tgz包
[root@master ~]# yum -y install openssl-devel bzip2-devel expat-devel
gdbm-devel readline-devel sqlite-devel libffi-devel gcc gcc-c++3、 解压缩,指定安装路径
[root@master ~]# tar zxvf Python-3.7.0.tgz
[root@master ~]# ls
[root@master ~]# cd Python-3.7.0/[root@master Python-3.7.0]# ls
[root@master Python-3.7.0]# ./configure --prefix=/usr/local/python3 #安装路径
4、 编译安装
[root@master Python-3.7.0]# make -j3 提速利用线程
[root@master Python-3.7.0]# make install
[root@master Python-3.7.0]# cd /usr/local/[root@master local]# ls
[root@master local]# cd python3/[root@master python3]# ls
[root@master python3]# cd bin/[root@master bin]# ls
[root@master bin]# ./python3.7 查看python信息
安装python3.7版本完成
5、 创建软链接(优化)
[root@master bin]# ln -s /usr/local/python3/bin/python3.7/usr/bin/python3
[root@master bin]# python3 #对应的是刚安装上的新版本
Python 3.7.0(default, Jan 132021,01:13:03)[GCC4.8.520150623(Red Hat 4.8.5-44)] on linux
Type "help","copyright","credits" or "license"for more information.>>>exit()[root@master bin]# python #对应的是旧版本
Python 2.7.5(default, Aug 42017,00:39:18)[GCC4.8.520150623(Red Hat 4.8.5-16)] on linux2
Type "help","copyright","credits" or "license"for more information.>>>exit()6、优化后,若想在linux中执行python,直接输入python3,就可进入新版本!