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?
This error will often occur when a newer version of python has been installed alongside an older version e.g;
Run a command that uses the apt_pkg module and get an error such as;
When we install a non-distro python3 version with apt it will set a shared module directory to be that of python3 most usually it will /usr/lib/python3.
Most of the time this will be ok, but under some circumstances the different versions of python rely on different libraries or shared objects/libraries then the other python version does so as other answers have pointed out we need to link the .SO to the correct python version. So if we have python3.6 installed on a 64bit system then the apt_pkg .SO link would be
But the problem lies in the fact that when we install a newer python version the link will update to point to the newest python version, which leads to the error of apt_pkg module not being found. By checking which version of python ships with your distro you can create the link as shown above. Or we use a method to offer the command a choice of python versions to link the .SO such as;
Because python will create this link to the newest installed python version we give the command the option to choose from 3 python versions, of which it will choose the highest version given.
Make sure you have a working python-apt package. You could try and remove and install that package again to fix the problem with apt_pkg.so not being located.
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.5The following code solved my problem,
So, obviously, python3-apt checks the highest python version, instead of the current python version in use.
For some reason my install was missing
apt_pkg.so
in the python3 dist-packages dir. (apt_pkg.cpython-33m-x86_64-linux-gnu.so
was there?!) but and I had to make a symlinkapt_pkg.so -> apt_pkg.cpython-33m-x86_64-linux-gnu.so
in/usr/lib/python3/dist-packages
I'm not sure whether my upgrade was broken or why this was the case. It occured after trying to upgrade (precise->raring->quantal upgrade)
Solve it by this:
/usr/lib/python3/dist-packages# cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so
Or:
/usr/lib/python3/dist-packages# cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
Basically, if you get a
No such file or directory
justls
to try to get the right name.Just in case it helps another, I finally solved this problem, that was apparently caused by python version conflicts, by redirecting the link python3, then redirecting it to the right python version:
You may need to enter the correct python version, found with: