1、打开python官网,点击download复制需要下载的python版本https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tgz
2、进行解压: tar -xvf Python-3.9.8.tgz
3、进入加压后的目录,python-3.9.8
4、./configure prefix=/usr/local/python3
5、make && make intall
编译出错:根据编译的提示,下载依赖包:gcc 与 libffi-devel
建立Python3和pip3的软链:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
6.并将/usr/local/python3/bin加入PATH
(1)vim /etc/profile
(2)按“I”,然后贴上下面内容:
# 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