1.安装依赖库
sudo apt-get install build-essential libbz2-dev libssl-dev libreadline-dev libsqlite3-dev
2.下载 Python 3.9 源代码
wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tar.xz
# 解压
tar -xf Python-3.9.5.tar.xz
3.编译Python 3.9
cd Python-3.9.5
./configure
make
4.安装Python 3.9
sudo make install
5.更新Python链接
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 1
然后自己验证一下安装的结果,在终端窗口输入python, python3 看版本信息输出是对的。