ImportError: No module named when trying to run Python script

If you are trying to run a script that includes other python scripts which are not in your Python Library, you will surely get this error “ImportError: No module named xxx when trying to run Python script”.

The above error says that you do not have some required modules which need to be installed.

Follow the steps below carefully to solve this error.


Step 1: Identify which module needs to be installed

  • For example, if you get an error like “ImportError: No module named numpy when…”. Here your module name is numpy.

Step 2: Install this module

  • Download this file get-pip.py by right-clicking on it and select save link as
  • Run this file as shown below.
    get-pip
  • You will see that a Scripts folder is created in your C:\Python27 (or any version) folder.

scipts

  • Now, moving further add the location C:\Python27\Scripts to your system environment variable path the same way you added the location C:\Python27.
  • So in your system variable path, you should see something like this.

system-variables

system-variables-python-path

  • Now that is all set, let’s install the missing module.
  • Run this command as shown below.

install-numpy


This module will get install successfully and you do not have to worry about it.

Now, you can proceed running your python script and you won’t get the same error again.

Do divert you still faced the same error. Let me know whether this post was helpful.

Mention in your comments below.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s