CentOS 7.6安装python3.7.0
1、安装依赖包(不安装也可以,但是后续可能会出现某些错误)
[root@py ~]# yum -y install zlib-devel bzip2-devel openssl-devel openssl-static ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel lzma gcc
[root@py ~]# yum -y groupinstall "Development tools"
2、下载python3.7.0安装包
[root@py ~]# cd /usr/local/src
[root@py src]# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
3、解压
[root@py src]# tar Jxvf Python-3.7.0.tar.xz
[root@py src]# mv Python-3.7.0 /usr/local/python-3.7
[root@py src]# cd /usr/local/python-3.7/
4、安装
[root@py python-3.7]# ./configure --prefix=/usr/local/sbin/python-3.7
[root@py python-3.7]# make && make install
安装完成后查看python命令指向(默认是指向python2.7)
[root@py ~]# which python
/usr/bin/python
[root@py ~]# ll /usr/bin/ |grep python
-rwxr-xr-x. 1 root root 11312 11月 14 2018 abrt-action-analyze-python
lrwxrwxrwx. 1 root root 35 9月 16 13:03 pip -> /usr/local/sbin/python-3.7/bin/pip3
lrwxrwxrwx. 1 root root 38 9月 16 13:01 python -> /usr/local/sbin/python-3.7/bin/python3 这里我是设置过的
lrwxrwxrwx. 1 root root 9 9月 16 12:10 python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 2018 python2.7
5、设置软连接
[root@py ~]# rm -rf /usr/bin/python #先将原来的指向删除
[root@py ~]# ln -s /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python
6、修改yum,使py2与py3共存
①将/usr/bin/yum的顶部的:
!/usr/bin/python 改成 !/usr/bin/python2.7
②将/usr/libexec/urlgrabber-ext-down的顶部的:
/usr/bin/python 改为 /usr/bin/python2.7
③将/usr/bin/yum-config-manager的顶部的
#!/usr/bin/python 改为 #!/usr/bin/python2.7
7、最后将pip指向到python3.7
[root@py ~]# ln -sf /usr/local/sbin/python-3.7/bin/pip3 /usr/bin/pip
pip版本为10.0.1,可以更新一下
[root@py ~]# python -m pip install --upgrade pip
仅记录自己的学习总结,如有错误,还请评论指正~