Ubuntu14.04安装Python2的python-dev等依赖包报错,求修复方案
Let's work through this step by step—this error usually pops up due to outdated package caches, unconfigured packages, held packages, or since Ubuntu 14.04 is end-of-life (EOL), your package sources might be pointing to retired servers. Here's how to fix it:
Step 1: Refresh package lists and upgrade existing packages
First, make sure your system's package info is up to date and all installed packages are current:
sudo apt-get update sudo apt-get upgrade
This ensures you're pulling the latest available versions (for 14.04's archived repos) and clears up any outdated cache that might be causing dependency mismatches.
Step 2: Fix broken dependencies and unconfigured packages
Run these commands to automatically repair missing dependencies and finish setting up any half-installed packages:
sudo apt-get -f install sudo dpkg --configure -a
The -f flag tells apt to "fix" broken dependencies, while dpkg --configure -a resolves any packages that were interrupted during installation.
Step 3: Check for held packages
The error mentions "held broken packages"—let's see if any packages are locked from updating:
dpkg --get-selections | grep hold
If you see output like libpython-dev hold or python2.7-dev hold, unlock them with:
sudo apt-mark unhold libpython-dev python2.7-dev
Held packages can block dependency resolution, so unlocking them often fixes the issue.
Step 4: Install dependencies directly, then your target packages
If the above steps don't work, try installing the missing dependencies first, then your original packages:
# Install the missing dependencies first sudo apt-get install python2.7-dev libpython-dev # Now install your desired packages sudo apt-get install python-dev libxml2-dev libxslt-dev
This forces apt to resolve the dependency chain for the required packages before installing the ones you need.
Step 5: Update your package sources (critical for Ubuntu 14.04 EOL)
Since Ubuntu 14.04 is no longer supported, the default package sources might be offline. Replace your /etc/apt/sources.list entries with the old releases archive:
- Backup your current sources list first:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak - Edit the sources list with your favorite editor (e.g., nano):
sudo nano /etc/apt/sources.list - Replace all instances of
http://archive.ubuntu.com/ubuntu/orhttp://us.archive.ubuntu.com/ubuntu/withhttp://old-releases.ubuntu.com/ubuntu/ - Save and exit (in nano: Ctrl+O, Enter, Ctrl+X)
- Run
sudo apt-get updateagain, then try installing the packages once more.
Why this happens
Ubuntu 14.04 reached end-of-life in April 2021, so official repositories are no longer maintained. This means dependency packages might be missing from your current sources, or your system has leftover broken packages from interrupted installs or outdated cache.
内容的提问来源于stack exchange,提问作者ChikChak

