Importerror No module named apt_pkg

Importerror No module named apt_pkg – Best ways to Fix

Popular Domains for just 99 Cents at Namecheap!

Importerror no module named apt_pkg is mainly because of python-apt package. Either python-apt package is not installed or incompatible. So the fix for this error (no module named apt_pkg) is straight to reinstall/ upgrade the python-apt package. There are many ways to achieve this. In this article, we will explore them one by one.

Importerror no module named apt_pkg  ( Solution ) –

Let’s see the various ways to install /reinstall/upgrade the apt_pkg.

Method 1:

In this step, we will use apt-get for installing the python-apt package.

apt-get install python-apt

If you are not an admin user, You may add sudo before this command.

sudo apt-get install python-apt

Method 2:

In some scenarios,  We need not uninstall the existing python-apt package. But if we reinstall it using the below command. It will replace the incompatible version with compatible/lastest one.

sudo apt-get install python3-apt --reinstall

Method 3:

If we look at the extension of this python-apt package. Its basically a  “.so” filetype. In some scenarios, It is not properly set at the location “/usr/lib/python3/dist-package” location. We can manually set the file at the exact location using the below command.

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

The correct file placement is also done in the below way.

cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.so

We have mostly covered ways of fixing the above bug. First help in installing the package, second deals with reinstallation and the third one is related to path set issue.

Conclusion –

apt_pkg is one of the most useful packages. Especially in the setup of other modules.  I hope you may easily fix this error with the above-mentioned methods. We have tried to cover most of the scenarios. But still, if you think something is left. Please let us know. We will surely help you in fixing the bug “no module named apt_pkg”.

You may also comment below in the comment box. I will appreciate you for reading this article till the end.

Thanks

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner