01.centos 7 安装 python 3.7.1
centos 7 安装 python 3.7.1
https://www.python.org/downloads/source/
在官网上下载 Python-3.7.1.tar.xz 安装包,在下载时可以看到有 XZ 和 Gzip 两种格式的压缩包,这两个都可以下载使用,只是 XZ 格式的压缩包体积会更小些。
一、安装 python3 依赖包
[root@localhost /]# yum -y groupinstall "Development tools"
[root@localhost /]# 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@localhost /]# mkdir /usr/local/python3.7.1 && cd /usr/local/python3.7.1/
[root@localhost python3.7.1]# tar -xvJf Python-3.7.1.tar.xz #这里我已经把 Python-3.7.1.tar.xz 软件包拷贝到此目录下了
[root@localhost python3.7.1]# cd Python-3.7.1/
[root@localhost Python-3.7.1]# ./configure --prefix=/usr/local/python3.7.1
[root@localhost Python-3.7.1]# make && make install
[root@localhost Python-3.7.1]# yum install libffi-devel -y
[root@localhost Python-3.7.1]# make install
三、配置软链接
[root@localhost Python-3.7.1]# ln -s /usr/local/python3.7.1/bin/python3 /usr/bin/python3
[root@localhost Python-3.7.1]# ln -s /usr/local/python3.7.1/bin/pip3 /usr/bin/pip3
[root@localhost Python-3.7.1]# python3
Python 3.7.1 (default, Dec 29 2018, 16:46:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
四、配置 python3/2 版本共存
[root@localhost Python-3.7.1]# vim /usr/bin/yum
#!/usr/bin/python2 //将原来的 python 改为 python2
[root@localhost Python-3.7.1]# vim /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2 //将原来的 python 改为 python2
五、查看版本信息
[root@localhost /]# python3 -V
Python 3.7.1
[root@localhost /]# python2 -V
Python 2.7.5