modulenotfounderror: no module named ‘numpy’

Python throws modulenotfounderror: no module named ‘numpy’, in four conditions –

  1. When you have multiple versions of python installed and you installed numpy on one version but using different one for running your code.
  2. When Python directory is not listed in environment path variables.
  3. When you have multiple virtual environments like CygWin and you are mixing things up.
  4. Numpy is not installed.

The solution of this numpy modulenotfound error is to check all the 4 conditions.

Installing numpy

If you are using Python3 then install numpy using this command –

python3 -m pip install numpy

or you can also use pip3 –

pip3 install numpy

for other python version use –

pip install numpy

Check Environment PATH

First check where your python is installed. It could be anywhere, but the most common locations are –

C:\Program Files\Python36\

C:\Python36

C:\Users\akash\AppData\Local\Programs\Python\Python36\

Where Python36 is Python version 3.6. Yours could be different so check that out. Also akash is my user but yours will be different.

Now, after getting python location, you can check the environment path variable if its included there or not. This guide will help you in setting paths.

Reinstall Python and Numpy

You can always try the most reliable solution of reinstalling.

pip3 uninstall numpy
pip3 install numpy

Virtual Environments

If you are running under virtual environments then make sure your different packages should also be inside the same environment. For example –

(venv) -> which python
/Users/akash/venv/bin/python
(venv) -> which ipython
/usr/bin/ipython

Here python is in different environment and ipython in different. Make sure your code loads the libraries from your environment only.

    Tweet this to help others