close

[Solved] python-dev installation error: ImportError: No module named apt_pkg

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error python-dev installation error: ImportError: No module named apt_pkg in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How python-dev installation error: ImportError: No module named apt_pkg Error Occurs?

Today I get the following error python-dev installation error: ImportError: No module named apt_pkg in python.

How To Solve python-dev installation error: ImportError: No module named apt_pkg Error ?

  1. How To Solve python-dev installation error: ImportError: No module named apt_pkg Error ?

    To Solve python-dev installation error: ImportError: No module named apt_pkg Error I met this problem when doing sudo apt-get update. My env is debian8, with python2.7 + 3.4(default) + 3.5.

  2. python-dev installation error: ImportError: No module named apt_pkg

    To Solve python-dev installation error: ImportError: No module named apt_pkg Error I met this problem when doing sudo apt-get update. My env is debian8, with python2.7 + 3.4(default) + 3.5.

Solution 1

I met this problem when doing sudo apt-get update. My env is debian8, with python2.7 + 3.4(default) + 3.5.

The following code will only re-create a apt_pkg....so file for python 3.5

sudo apt-get install python3-apt --reinstall

The following code solved my problem,

cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-{your-version-number}-x86_64-linux-gnu.so apt_pkg.so

Replace {your-version-number} appropriately.

So, obviously, python3-apt checks the highest python version, instead of the current python version in use.

Solution 2

This worked for me on after updating python3.7 on ubuntu18.04

cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read