1 下载python3的源码
cd /opt/yum install wget -ywget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
2 安装python3之前,先解决依赖环境,不然会出现很多麻烦,提前通过yum安装好这些软件包
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
3 解压源码包
tar -xvf Python-3.6.2.tgz
4 切换目录
cd Python-3.6.2
5 编译和安装
- 释放编译文件makefile,这个文件就是用来编译且安装的
cd Python-3.6.2/./configure --prefix=/opt/python36/
- 开始编译python3
make
- 编译且安装,会生成/opt/python36文件
make install
- 配置python3.6的环境变量
- 1 配置软连接(和path配置二选一)
ln -s /opt/python36/bin/python3.6 /usr/bin/python3 #此时还没有pipln -s /opt/python36/bin/pip3 /usr/bin/pip3
- 2 配置path环境变量(软连接配置完可省略此步骤)
# 编辑一个全局个人配置文件vim /etc/profile# 在最下方写入环境变量PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/python36/bin# 保存退出#最后读一下生效source /etc/profile
配置完毕 可以尝试安装一个django试试
pip3 install django# 偷偷告诉你 加上-i https://pypi.tuna.tsinghua.edu.cn/simple下载更快哦