In Python, if you try to import numpy
without installing the module using pip, you will get ModuleNotFoundError: No module named ‘numpy’ error.
In this tutorial, let’s look at installing the numpy
module correctly in different operating systems and solve no module named numpy error.
ModuleNotFoundError: No module named ‘numpy’
Numpy
are not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it.
There are various reasons why we get the ModuleNotFoundError: No module named ‘numpy’ error
- Trying to use NumPy without having the numpy package installed
- The IDE you are using is not set to the incorrect Python version.
- You are using the virtual environment and not installed the numpy in a virtual environment
- Installing the NumPy package in a different version of Python than the one which is used currently.
- Declaring a variable name as numpy
If you are getting an error installing pip, checkout pip: command not found to resolve the issue.
Install NumPy in OSX/Linux
The recommended way to install the NumPy module is using pip or pip3 for Python3 if you have installed pip already.
Using Python 2
$ sudo pip install numpy
Using Python 3
$ sudo pip3 install numpy
Alternatively, if you have easy_install
in your system, you can install NumPy using the below command.
Using easy install
$ sudo easy_install -U numpy
For CentOs
$ yum install numpy
For Ubuntu
To install the NumPy module on Debian/Ubuntu :
$ sudo apt-get install python-numpy
Install NumPy in Windows
In the case of windows, you can use pip or pip3 based on the Python version; you have to install the NumPy module.
$ pip3 install numpy
If you have not added the pip to the environment variable path, you can run the below command in Python 3, which will install the NumPy module.
$ py -m pip install numpy
Install NumPy in Anacodna
If you use conda
, you can install NumPy from the defaults
or conda-forge
channels:
# Best practice, use an environment rather than install in the base env
conda create -n my-env
conda activate my-env
# If you want to install from conda-forge
conda config --env --add channels conda-forge
# The actual install command
conda install numpy