Skip to content
Home » ImportError: No module named apt_pkg

ImportError: No module named apt_pkg

To solve python-dev installation error: ImportError: No module named apt_pkg error follow below methods.

ERROR LOG

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

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

Refer the given methods to solve the issue.

Method 1:

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

sudo apt-get install python3-apt --reinstall

Run the following code to solve the issue,

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 in the above code.

The following will build a symbolic link between apt pkg37m and apt pkg36m. By ll apt pkg.cpython-*, you can ensure that you are linking to the proper, or at least an existing version, and see which one(s) you have installed.

sudo ln -s apt_pkg.cpython-{36m,37m}-x86_64-linux-gnu.so

Method 2 :

cd /usr/lib/python3/dist-packages
cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so

Hope the above solution works.

Also read :

error: Setup script exited with error: command ‘gcc’ failed with exit status 1
ValidJSONDecodeError: Expecting , delimiter