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

结果如下:

相关推荐
AI攻城狮2 小时前
用 Playwright 实现博客一键发布到稀土掘金
python·自动化运维
曲幽3 小时前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
孟健18 小时前
Karpathy 用 200 行纯 Python 从零实现 GPT:代码逐行解析
python
码路飞20 小时前
写了个 AI 聊天页面,被 5 种流式格式折腾了一整天 😭
javascript·python
曲幽1 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
敏编程1 天前
一天一个Python库:jsonschema - JSON 数据验证利器
python
前端付豪1 天前
LangChain记忆:通过Memory记住上次的对话细节
人工智能·python·langchain
databook1 天前
ManimCE v0.20.1 发布:LaTeX 渲染修复与动画稳定性提升
python·动效
花酒锄作田2 天前
使用 pkgutil 实现动态插件系统
python