How to pip install numpy to fix the modulenotfound error ?

In today’s recipe we’ll discuss how to fix the pretty ubiquitous modulenotfounderror: no module named ‘numpy’ error on MAC , Linux Ubuntu and Windows 10 operating systems.

You typically get the error when working on Jupyter Notebook / Lab or when using your favorite Python IDE such as PyCharm, Spyder or others.

The error can occur either when working on standard Python installations, virtual environments and when using Environment Manager such as Anaconda or Miniconda.

Numpy module not found error

The module not found error is thrown when Python can’t find the package in your computer and has to be fixed by loading it from the Python Package Index repository. Here’s how to fix:

  • Save your work and close Jupyter / PyCharm / Eclipse / Spyder / VSCode or other development environments you might be using
  • Open your Terminal / Command prompt and point to your environment directory.
  • Type the following
pip install numpy
  • Hit Enter.
  • The Numpy package will be be collected and downloaded from the Python Package repository into your environment.
  • Re-open Jupyter or your IDE and try to import Numpy using
import numpy as np

Anaconda environments

The Numpy package is installed when you use the default Anaconda distribution, which contains pretty much all data analysis and data sciences you might need.

If you decided to skip Anaconda, and instead use Miniconda and install your Python packages manually you should proceed as following:

  • Open the Anaconda Command Prompt
  • Activate your Conda Virtual Environment using the following command: conda activate <path_to_your_environment>
  • Then install Numpy using this command: conda install numpy
  • The Numpy package will be collected and downloaded into your environment.
  • Close the Anaconda Command Prompt.
  • Re-open Jupyter or your favorite Python IDE and import Numpy.

Kindly leave us a comment in case of follow up questions.

Leave a Comment