一、下载Python3.6.8
下载
curl -O https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
解压
tar -zxvf Python-3.6.8.tgz
二、编译
安装gcc、zlib,用于编译,如果已经安装可略过。
yum install -y gcc
yum install -y zlib*
到解压的目录,执行编译。 跟上–prefix=/usr/local/python3可控制python的安装目录。
cd Python-3.6.8
./configure --prefix=/usr/local/python3
用make命令编译python
make install
三、建立python3的软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
并将/usr/local/python3/bin 加入path
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
执行环境变量生效命令
# source ~/.bash_profile
四、检验安装成果
检查Python3及pip3是否正常可用:
python3 -V
Python 3.6.8
pip3 -V
pip 18.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)