在 Ubuntu 上更新 Python 版本,您可以按照以下步骤操作:
打开终端(快捷键:Ctrl + Alt + T)
首先,确保系统已安装了所需的依赖项。运行以下命令来安装它们:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
apt-cache search python | grep -E '^python[0-9]+'
sudo apt-get install python3.9
python3.9 --version
这将显示您刚刚安装的 Python 版本。
update-alternatives
命令。首先,为所有 Python 版本配置 update-alternatives:sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
然后,选择您想要的默认版本:
sudo update-alternatives --config python3
按照提示操作,选择您希望设置为默认的 Python 版本。
现在,您已经在 Ubuntu 上成功更新了 Python 版本。