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

Belphegor picture Belphegor · Dec 4, 2012 · Viewed 175.2k times · Source

I am Debian user, and I want to install python-dev, but when I run the code in the shell as a root:

# aptitude install python-dev

I get the following error:

Traceback (most recent call last):       
  File "/usr/bin/apt-listchanges", line 28, in <module>
    import apt_pkg
ImportError: No module named apt_pkg

What seems to be the problem and how can I resolve it?

Answer

zhazha picture zhazha · Mar 26, 2016

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-{35m,34m}-x86_64-linux-gnu.so

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