Importerror No module named apt_pkg – Best ways to Fix

Importerror No module named apt_pkg

Importerror no module named apt_pkg is mainly because of python-apt package. Either python-apt package is not installed or is 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. The below command is for the Linux Operating System.

apt-get install python-apt

If you are not an admin user, You may add sudo before this command. It will ask for the password enter and then use the below command.

sudo apt-get install python-apt
installing python apt package as an admin
installing python apt package as an admin

Method 2:

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

sudo apt-get install python3-apt --reinstall

Method 3:

If we look at the extension of this python-apt package. It’s basically a  “.so” file type. 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 above command will copy the apt_pkg.cpython-34m-i386-linux-gnu.so to 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

That’s all you have to do. Here We have mostly covered ways of fixing the above bug. The first helps in installing the package, the second deals with reinstallation and the third one is related to the path set issue.

 

Conclusion –

The 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.

Meet Abhishek ( Chief Editor) , a data scientist with major expertise in NLP and Text Analytics. He has worked on various projects involving text data and have been able to achieve great results. He is currently manages Datasciencelearner.com, where he and his team share knowledge and help others learn more about data science.
Share via
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner