1.到官网下载适合自己的版本
Python Source Releases | Python.orgThe official home of the Python Programming Languagehttps://www.python.org/downloads/source/2.下载好压缩包之后,将压缩包解压开
3.将开发环境的依赖包准备好
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel libffi-devel gcc make
4.编译安装
进入到解压好的目录
执行命令
./configure --prefix=/usr/local/tools/Python-3.6.8
make
make install
注:--prefix是Python的安装目录。
没有提示错误,说明编译安装成功。
5.建立python和pip的软连接
ln -s /usr/local/tools/Python-3.6.8/bin/python3.6 /usr/bin/python3
ln -s /usr/local/tools/Python-3.6.8/bin/pip3.6 /usr/bin/pip3
到/user/bin 下确认软链是否建立完成
6.配置环境变量
vi ~/.bash_profile
export PYTHON_HOME=/usr/local/tools/Python-3.6.8
export PATH=$PYTHON_HOME/bin:$PATH
source ~/.bash_profile
7.执行python3,看是否能进入到python
8.执行 echo $PYTHON_HOME,查看环境变量是否生效