Software⏱️ 2 min read📅 2026-06-03

How to Fix: python-dev installation error: ImportError: No module named apt_pkg

apt_pkg not found during python-dev installation on Debian.

Quick Answer: Try reinstalling apt and apt-utils packages, or upgrade to a newer version of Debian.

The error you're experiencing is likely due to a recent change in the apt package manager, which has removed the apt_pkg module. This module was used by the python-dev package to handle dependencies.

🛠️ Step-by-Step Verified Fixes

Method 1: Reinstalling python-dev

  1. Step 1: Run the following command to reinstall python-dev:
# apt-get install --reinstall python-dev

Method 2: Installing libapt-installer4-dev and libapt-pkg3.0-dev

  1. Step 1: Run the following command to install the required packages:
# apt-get install libapt-installer4-dev libapt-pkg3.0-dev

🎯 Final Words

To avoid this issue in the future, you can use the following command to install python-dev without reinstalling:

# apt-get install --reinstall libapt-pkg3.0-dev

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions