一.安装python3.6.1
1.安装依赖环境(必须安装否则会出现python3编译器中不能使用退格键和方向键)
yum install readline-devel gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel
 
2.下载安装并解压
mkdir /home/python3
cd /home/python3
 
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
tar zvxf Python-3.6.1.tgz
 
3.编译并安装
cd Python-3.6.1 ##进入安装包
mkdir /usr/local/python3 ##创建安装目录
./configure --prefix=/usr/local/python3 ##编译
make && make install ##安装
 
4.创建软连接
mv /usr/bin/python /usr/bin/python_bak ##备份原软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python ##chua创建新的软链接使程序运行时不显示版本号
 
5.测试是否正常
[root@node1 Python-3.6.1]# python
Python 3.6.1 (default, Apr 21 2018, 16:42:07)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
 
6.将/usr/local/python3/bin加入到环境变量
[root@node1 Python-3.6.1]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
[root@node1 Python-3.6.1]# source ~/.bash_profile ##使环境变量生效
[root@node1 Python-3.6.1]# python3 -V ##测试python3正常
Python 3.6.1
[root@node1 Python-3.6.1]# pip3 -V ##测试pip3正常
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
 
7.修改yum指向python旧版本
[root@node1 pip-8.0.2]# vi /usr/bin/yum
#!/usr/bin/python2.6
 
二.安装pip及setuptools
1.安装pip前需要前置安装setuptools
mkdir /home/setuptools
cd /home/setuptools
 
[root@node1 ~]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
[root@node1 ~]# tar zxvf setuptools-19.6.tar.gz
[root@node1 ~]# cd setuptools-19.6
[root@node1 ~]# python3 setup.py build
[root@node1 ~]# python3 setup.py install
 
2.安装pip
[root@node1 ~]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
[root@node1 ~]# tar zvxf pip-8.0.2.tar.gz
[root@node1 ~]# cd pip-8.0.2
[root@node1 pip-8.0.2]# python3 setup.py build
[root@node1 pip-8.0.2]# python3 setup.py install