No module Named NumPy

Table of Contents What is “NumPy”?No module named NumPy:What is no module named NumPy?When does it occur?How can we solve “No module named NumPy”?When you have not installed the NumPy library in your system.No module …

What is “NumPy”?

NumPy is the fundamental package of python used for scientific calculations.

It consists of a bundle of features:

Powerful N-dimensional arrays, numerical computing tools, interoperable, performant and it is easy to use, plus it is open-source.

 Now, when we know what NumPy is, then let’s move to the actual topic:

No module named NumPy:

In this piece of article, we will discuss:

  • What is no module named NumPy?
  • When it occurs?
  • How can we solve this?

What is no module named NumPy?

NumPy is one of python’s external modules since python has several external modules.“No module named NumPy” is an error in a module when you import the NumPy library in your program and execute that program it will throw an error at the time of execution.

importError: ModuleNotFoundError: no module named ‘NumPy’.

When does it occur?

  • When you have not installed the NumPy library in your system.

As NumPy is not a built-in library in python, to use it you must have to install it first. If the NumPy library is not installed and you are accessing it then it will throw the error “no module named NumPy”

  • When the directory path is not set correctly.

When the NumPy library is installed in your system but still not executing the program and at the time of execution it is throwing the error “no module named NumPy”.

The path of the directory is not set correctly, or we are using the wrong path to locate a NumPy.

  • While working with different virtual environments.

When we work on python, we use different IDE’s to  execute the python program like:

PyCharm, Anaconda, Jupiter Notebook, and many others, these IDE’s create their virtual environment to keep this separated from the global python.

  • It downloaded and still not working and showing the error message.

Also, if you have local files or any python file saved as numpy.py, the machine will get confused and that can also raise this error.

How can we solve “No module named NumPy”?

Let’s  begin with  the solution to those reasons which we discussed above :

When you have not installed the NumPy library in your system.

As we said above the main reason to trigger the error “no module named NumPy” is NumPy is not installed on your system.

To rectify this error, we will install the NumPy library:

No module named NumPy on windows:

To install NumPy on Windows Operating System we will use the command below:

For Python2:

pip install numpy

 For Python3:

pip3 install numpy

No Module Named NumPy on Linux:

To install NumPy on Linux Operating System and mac Operating System we will use the command below:

For python2:

sudo pip install numpy

For python3:

sudo pip3 install numpy

When the directory path is not set correctly.

When we use the import function, to import any module in the python program then python will search that module in specific directories and when it cannot find that module in those directories then it will throw the error “no module named XYZ”.

Now, how would we know which directories python will search?

To know which directories python will search we will use the command given below on the python prompt:

Import sys
Print(sys.path)

When the search completes, and it will show you the list of directories then make sure that your NumPy is stored in one of these directories.

If you cannot find your NumPy  module in any of those directories, then to search the python path use the commands below to your python prompt :

Import sys
sys.path.append(“NumPy_path”)
import NumPy 

While working with different virtual environments.

When we work on python, we use different IDEs to  execute the python program like:

PyCharm, Anaconda, Jupiter Notebook, and many others, these IDEs create their virtual environment to keep this separated from the global python.

In these consequences, if you have installed NumPy on your global python system you cannot use it in the virtual environment because it has separate package management.

No module named NumPy in PyCharm:

PyCharm has its small anaconda environment, and when the NumPy is missing in it then it will throw the error “no module named NumPy”.

To install the NumPy on PyCharm follow the steps below:

  1. Open the PyCharm Settings.
  2. Inside the PyCharm interpreter, Select the python packages system.
  3. Look for NumPy in the list.
  4. Then, select install.

If it is already installed, then check for the updated version and update it.Note: After installation or updating restart your PyCharm.

No module named NumPy in Anaconda:

Anaconda has its environment named “conda” to run the python.

Anaconda has a separate environment other than the global python and it is the reason that it can also encounter the no module named NumPy error.

Well, NumPy is automatically installed in anaconda but if it is not installed then you can install it by using the command below to avoid this error:

conda install numpy

You will run this command in Anaconda  Prompt.

No module named NumPy in Jupiter:

If you have installed Jupiter by using an anaconda environment, then installing the NumPy on Jupiter environment is the same as it was in an anaconda environment.

Use the same command in the anaconda prompt.

Conclusion

In this article, “No module named NumPy” we discussed in detail what is it, when does it occur and how can we solve this error, and also its possible solution in different environments.

Suggested Read: Remove Brackets from list Python

Leave a Comment