一.下载python3源码包
cd /tmp/
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
二.下载python3编译的依赖包(复制粘贴)
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
#gcc :c编译器 #python-devel python 开发包 #openssl-devel 用于pythn的ssl模块 #sqlite-devel 轻量级数据库
三 解压
tar -xvf Python-3.6.2.tgz
四 进入源码包
cd Python-3.6.2
五 编译且安装
1 指定安装目录
./configure --prefix=/opt/python/ --prefix 这个参数 是制定一个安装路径 /opt/python36/bin/python
2 编译并安装
make & make install
六 配置python3的环境变量
1 获取python3的解析器的位置
/opt/python/bin
2 获取系统环境变量
$PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
3 读取配置文件/etc/profile
vim /etc/profile
PATH=/opt/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin