1. 安装依赖环境
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
2. 下载 Python 3.6.5
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3. 创建安装目录
mkdir -p /usr/local/python3
4. 解压文件
tar -zxvf Python-3.6.5.tgz
5. 编译安装
cd Python-3.6.5
./configure --prefix=/usr/local/python3
make
make install
6. 建立Python3 的软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
7. 并将/usr/local/python3/bin加入PATH
vim ~/.bash_profile
修改以下代码:
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
使用以下命令,使修改生效:
source ~/.bash_profile
8. 检查是否安装完成
python3
出现以下代码表示安装完成:
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>