ubuntu20 安装python2

1. 确保启用了 Universe 仓库

在某些情况下,python2-minimal 包可能位于 Universe 仓库中。你可以通过以下命令启用 Universe 仓库并更新软件包列表:

bash复制

复制代码
sudo add-apt-repository universe
sudo apt update

然后尝试安装:

bash复制

复制代码
sudo apt install python2-minimal

如果仍然无法安装,可以尝试安装 python2python2.7

2. 安装 Python 2.7

在较新的 Ubuntu 版本中(如 Ubuntu 20.04 及以上),python2-minimal 包可能已被移除,但你可以安装 python2.7

bash复制

复制代码
sudo apt update
sudo apt install python2.7

3、使用 update-alternatives 配置 Python

如果你需要将 Python 2 设置为默认的 Python 解释器,可以使用 update-alternatives

复制代码
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

这样,当你运行 python 命令时,它将指向 Python 2.7。

设置 Python 3 为默认解释器 : 假设你的 Python 3 的路径是 /usr/bin/python3,运行以下命令:

bash复制

复制代码
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1

如果运行没有生效,可以手动替换添加。

复制代码
sudo update-alternatives --config python

结果如下:

相关推荐
郭庆汝1 小时前
pytorch、torchvision与python版本对应关系
人工智能·pytorch·python
思则变4 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
漫谈网络5 小时前
WebSocket 在前后端的完整使用流程
javascript·python·websocket
try2find6 小时前
安装llama-cpp-python踩坑记
开发语言·python·llama
博观而约取7 小时前
Django ORM 1. 创建模型(Model)
数据库·python·django
精灵vector9 小时前
构建专家级SQL Agent交互
python·aigc·ai编程
Zonda要好好学习9 小时前
Python入门Day2
开发语言·python
Vertira9 小时前
pdf 合并 python实现(已解决)
前端·python·pdf
太凉9 小时前
Python之 sorted() 函数的基本语法
python
项目題供诗9 小时前
黑马python(二十四)
开发语言·python