获取资源
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
wget未安装:yum install wget -y
安装依赖
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make -y
解压安装
[root@CentOS7 ~]# cd /usr/local/src/
[root@CentOS7 ~]# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
[root@CentOS7 src]# tar -Jxvf Python-3.6.2.tar.xz
[root@CentOS7 src]# cd Python-3.6.2
[root@CentOS7 Python-3.6.2]# ./configure prefix=/usr/local/python3 && make && make install
链接
[root@CentOS7 Python-3.6.2]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@CentOS7 Python-3.6.2]# ll /usr/bin/py*
-rwxr-xr-x. 1 root root 78 Apr 11 2018 /usr/bin/pydoc
lrwxrwxrwx. 1 root root 7 Jul 5 11:00 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root 9 Jul 5 11:00 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Apr 11 2018 /usr/bin/python2.7
lrwxrwxrwx. 1 root root 30 Nov 16 15:04 /usr/bin/python3 -> /usr/local/python3/bin/python3
或者设置默认为3版本,但是得修改yum配置
[root@CentOS7 Python-3.6.2]# vim /usr/bin/yum
#!/usr/bin/python 修改为 #!/usr/bin/python2
[root@CentOS7 Python-3.6.2]# vim /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python 也要修改为 #! /usr/bin/python2
配置pip
Python3装完后,默认已经安装了pip,此时只要配置下软链接即可使用pip工具:
[root@CentOS7 Python-3.6.2]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3