ubuntu20 安装python2

1. 确保启用了 Universe 仓库

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

bash复制

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

然后尝试安装:

bash复制

复制代码
sudo apt install python2-minimal

如果仍然无法安装,可以尝试安装 python2 或 python2.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

结果如下:

相关推荐
M--Y12 小时前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
岁月宁静13 小时前
DeepSeek Harness 实战与架构解析:让 Agent 从“会聊”到“能交付”
人工智能·python·agent
LiaoWL12313 小时前
NumPy 入门实战(二):向量化与余弦相似度——从 ndarray 到 Embedding
python·numpy·embedding
forest_0913 小时前
多 Agent 协作第二课:交叉验证≠独立验证
人工智能·python·算法·机器学习·prompt·agi
databook17 小时前
时间序列数据,先拆规律还是先查异常
python·数据挖掘·数据分析
师夷长技以自愈17 小时前
手搓 AI Agent 第 8 篇:从手写循环到画流程图——LangGraph 封装
人工智能·python
aifannihao18 小时前
Rust 1.100 的 DropGuard:用 Python 实测失败回滚与吞异常
python·rust·异常处理·标准库·contextlib
用户0190275816120 小时前
天勤 tqsdk 能做 A 股行情吗?期货强项与股票数据选型
python
2601_9679791221 小时前
pip在Python中的9个必须知道的用法
python·pip·版本控制·包管理工具·requirements.txt
曲径海盗21 小时前
【Python 学习第 58 天】列表方法
python·学习笔记·编程入门