Python MK007  

ImportError: No module named ‘Package Name’

Import Error: No Module Named ‘Packages’

Hi Geeks,

In this post, am going to show you how to solve the ImportError. The steps followed in this post is same to all other Linux distributions.

Why ImportError was occurred ?

The ImportError is raised when an import statement has trouble successfully importing the specified module. Typically, such a problem is due to an invalid or incorrect path, which will raise a ModuleNotFoundError or ImportError in Python 3.6 and newer versions.

Traceback (most recent call last):
  File "mountain.py", line 28, in ?
    from toolkit.interface import interface
ImportError: No module named toolkit.interface

Solution for ImportError:

In your system you want to install the missed python packages manually. There are three methods are available for downloading the missed packages.

Method 1:

In your system you want to install the missed python packages. No need for installing the missed packages manually. Simply update and upgrade your system. Finally reboot it.

Open a terminal and run the following commends,

mk007@linuxlia:~$ sudo apt-get update
mk007@linuxlia:~$ sudo apt-get dist-upgrade
mk007@linuxlia:`$ sudo reboot

 

Method 2:

PIP:

pip is a package-management system written in Python used to install and manage software packages. It connects to an online repository of public and paid-for private packages, called the Python Package Index.

For me google packages are missing. So the following error message was printed.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'google'

Open a terminal and run the following pip command, (In this command replace google to ‘missed package’)

mk007@linuxlia:~$ sudo pip install google

But sometimes this command also encountered by the same error. Then follow the second method.

 

Method 3:

In this method, am going to download the google module in there official site and setup it to the python packages.

For me google packages are missing.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'google'

  • After downloading the zip package, first of all extract it.
  • Open the terminal and switch the directory to where the extracted module was located.
  • Now run the following command for adding the package to python.
mk007@Linuxlia:~/Downloads/Google $ python setup.py install

Conclusion:

If you have any doubts about this post please leave a comment. Am ready to solve your doubts.

Leave A Comment