在 Ubuntu 中安装指定版本的 Python

更新包列表

sudo apt update

安装 software-properties-common 以便使用 add-apt-repository 命令

sudo apt install software-properties-common

添加 deadsnakes PPA(这是一个包含多个 Python 版本的 PPA)

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

安装指定版本的 Python,例如 Python 3.8

sudo apt install python3.8

验证安装

python3.8 --version

如果需要将这个版本设置为默认的 Python 版本,可以使用 update-alternatives 命令

添加 Python 版本到 update-alternatives

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1

配置默认版本

sudo update-alternatives --config python3

你可能感兴趣的:(ubuntu,python,linux)