1. 安装依赖包
sudo yum install gcc openssl-devel bzip2-devel libffi-devel
2. 下载Python
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz
3. 解压缩Python的源码压缩文件
tar -xf Python-3.7.4.tar.xz
4. 配置、编译、安装三部曲
./configure --prefix=/opt/python #安装路径根据自己需要设置 make make install
5. 创建软连接
cd /opt/python/bin ln -s python3.7 python
6. 将python所在路径添加到PATH变量
sed -i 's!PATH=!PATH=/opt/python/bin:!' ~/.bash_profile . ~/.bash_profile
7. 验证
[marlonm@centos7 bin]$ which python /opt/python/bin/python [marlonm@centos7 bin]$ python -V Python 3.7.4
8. 创建virtualenv (可选,如不使用virtualenv,可略过此步)
[marlonm@centos7 ~]$ cd /opt/ [marlonm@centos7 ~]$ python -m venv env [marlonm@centos7 opt]$ source env/bin/activate (env) [marlonm@centos7 opt]$ which python /opt/env/bin/python