先下载python的版本
安装依赖环境
# 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
安装python3
个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
# mkdir -p /usr/local/python3
解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同而不不同,如:我下载的是Python3.6.1.那我这里就是Python-3.6.1.tgz)
# tar -zxvf Python-3.x.x.tgz
进入解压后的目录,编译安装
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3 --enable-shared --with-ssl
make
make install
或者直接
make && make install
建立python3的软链
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
修改pip的软链接:ln -s /root/python36/bin/pip3 /usr/bin/pip ##可以忽略
将python3 bin目录加入PATH
打开profile文件
# vim /etc/profile
在最后加入下边两行
PATH=$PATH:/usr/local/python3/bin
export PATH