关于2026年在Ubuntu 24.04.03 LTS虚拟机中无法安装MIT 6.828要求的python2的解决方案

阅前声明
本教程只适用于标题所述环境下遇到的特定问题的解决方案,虽然在技术上对于类似场景的问题解决可能同样有效,但是不保证可行性,请读者自行测试,测试前务必做好快照备份
测试环境:Windows11专业版、VMware Workstation Pro 25H2

前言

在2026年的Ubuntu 24.04.03 LTS中,一键安装python2实在是一项难事image
于是笔者将自己的解决方案发布于博客园,希望能帮助到各位有需要的读者

由上图可知,ubuntu24.04 移除了 'python2' 这个元包;
笔者尝试过添加 deadsnakes PPA 源安装 Python 2.7,但也宣告失败

点击查看代码
tomato@tomato-VMware-Virtual-Platform:~$ sudo apt install python2.7
[sudo] tomato 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
E: 无法定位软件包 python2.7
E: 无法按照 glob ‘python2.7’ 找到任何软件包
tomato@tomato-VMware-Virtual-Platform:~$ sudo apt install software-properties-common -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
software-properties-common 已经是最新版 (0.99.49.3)。
software-properties-common 已设置为手动安装。
下列软件包是自动安装的并且现在不需要了:
  libllvm19
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
tomato@tomato-VMware-Virtual-Platform:~$ sudo add-apt-repository ppa:deadsnakes/ppa -y
软件源:“Types: deb
URIs: https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/  
Suites: noble
Components: main
”
描述:
This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
===========
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues
================

Issues can be reported in the master issue tracker at:
https://github.com/deadsnakes/issues/issues  

Supported Ubuntu and Python Versions
====================================

- Ubuntu 22.04 (jammy) Python3.7 - Python3.9, Python3.11 - Python3.13
- Ubuntu 24.04 (noble) Python3.7 - Python3.11, Python3.13
- Note: Python 3.10 (jammy), Python3.12 (noble) are not provided by deadsnakes as upstream ubuntu provides those packages.

Why some packages aren't built:
- Note: for jammy and noble, older python versions requre libssl<3 so they are not currently built
- If you need these, reach out to asottile to set up a private ppa

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.

Packages
========

The packages provided here are loosely based on the debian upstream packages with some modifications to make them more usable as non-default pythons and on ubuntu.  As such, the packages follow debian's patterns and often do not include a full python distribution with just `apt install python#.#`.  Here is a list of packages that may be useful along with the default install:

- `python#.#-dev`: includes development headers for building C extensions
- `python#.#-venv`: provides the standard library `venv` module
- `python#.#-distutils`: provides the standard library `distutils` module
- `python#.#-lib2to3`: provides the `2to3-#.#` utility as well as the standard library `lib2to3` module
- `python#.#-gdbm`: provides the standard library `dbm.gnu` module
- `python#.#-tk`: provides the standard library `tkinter` module

Third-Party Python Modules
==========================

Python modules in the official Ubuntu repositories are packaged to work with the Python interpreters from the official repositories. Accordingly, they generally won't work with the Python interpreters from this PPA. As an exception, pure-Python modules for Python 3 will work, but any compiled extension modules won't.

To install 3rd-party Python modules, you should use the common Python packaging tools.  For an introduction into the Python packaging ecosystem and its tools, refer to the Python Packaging User Guide:
https://packaging.python.org/installing/  

Sources
=======
The package sources are available at:
https://github.com/deadsnakes/  

Nightly Builds
==============

For nightly builds, see ppa:deadsnakes/nightly https://launchpad.net/~deadsnakes/+archive/ubuntu/nightly  
更多信息:https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa  
正在添加源。
命中:1 http://sg.archive.ubuntu.com/ubuntu noble InRelease
命中:2 http://sg.archive.ubuntu.com/ubuntu noble-updates InRelease            
命中:3 http://sg.archive.ubuntu.com/ubuntu noble-backports InRelease          
命中:4 http://security.ubuntu.com/ubuntu noble-security InRelease             
获取:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu   noble InRelease [17.8 kB]
获取:6 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu   noble/main amd64 Packages [33.8 kB]
获取:7 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu   noble/main Translation-en [5,904 B]
已下载 57.5 kB,耗时 2秒 (24.2 kB/s)        
正在读取软件包列表... 完成
tomato@tomato-VMware-Virtual-Platform:~$ sudo apt update
命中:1 http://sg.archive.ubuntu.com/ubuntu noble InRelease
命中:2 http://sg.archive.ubuntu.com/ubuntu noble-updates InRelease            
命中:3 http://sg.archive.ubuntu.com/ubuntu noble-backports InRelease          
命中:4 http://security.ubuntu.com/ubuntu noble-security InRelease             
命中:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu   noble InRelease
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
所有软件包均为最新。
tomato@tomato-VMware-Virtual-Platform:~$ sudo apt install python2.7 -y
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
E: 无法定位软件包 python2.7
E: 无法按照 glob ‘python2.7’ 找到任何软件包
tomato@tomato-VMware-Virtual-Platform:~$ 

🔧解决方案:手动编译 Python 2.7

⚠️ 此方案较复杂,仅当你熟悉 Linux 编译流程时推荐。

1. 安装编译依赖

sudo apt install -y build-essential checkinstall zlib1g-dev libncurses5-dev \
  libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev \
  libsqlite3-dev wget libbz2-dev tk-dev

2. 下载并编译 Python 2.7.18(最后一个 2.x 版本)

# 下载源码
cd /tmp
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar -xzf Python-2.7.18.tgz
cd Python-2.7.18

# 配置 + 编译(安装到 /opt/python2.7,避免冲突)
./configure --prefix=/opt/python2.7 --enable-optimizations
make -j$(nproc)
sudo make install

3. 创建软链接并验证

sudo ln -sf /opt/python2.7/bin/python2.7 /usr/local/bin/python2
sudo ln -sf /opt/python2.7/bin/pip2.7 /usr/local/bin/pip2

python2 --version  # 应输出 Python 2.7.18

效果如图
image

4. 配置 QEMU 时指定 python2 路径

cd qemu
./configure --disable-kvm --disable-werror --prefix=/usr/local \
            --target-list="i386-softmmu,x86_64-softmmu" \
            --python=/usr/local/bin/python2
posted @ 2026-03-04 00:25  tomatoo  阅读(12)  评论(0)    收藏  举报