Diagram
ModuleNotFoundError: No module named ‘apt_pkg’ error occurs when “python-apt package is not installed or is incompatible.“
How to fix the error?
Here are three ways to fix the ModuleNotFoundError: No module named ‘apt_pkg’ error.
- Install python-apt package.
- Reinstall the python-apt package.
- Set the correct location of the package.
Solution 1: Install the python-apt package
The easy way to fix this is by installing the python-apt package using the below command.
sudo apt-get install python-apt
It will ask for admin access; you must provide one to install the python-apt package.
Solution 2: Reinstall the python-apt package
You can reinstall the python-apt package using the “sudo apt install –reinstall python3-apt” command in your terminal.
If you still face the issue, try running the installation command with the –fix-missing flag.
sudo apt install python3-apt --fix-missing
If the error persists, try running the command with the –fix-broken flag.
sudo apt install python3-apt --fix-broken
You can also reinstall python3-apt using these series of commands:
sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt
Solution 3: Set the correct location of the package
The extension of the python-apt package is the “.so” file type.
To set the file at the exact location, use the below command.
/usr/lib/python3/dist-packages# cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so
This will fix the error you are having!
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.