Python has many external modules which are helpful to manage data efficiently. Numpy is one of those modules to handle arrays or any collection of data with ease. With many available methods, you can directly modify and edit the data according to your need. Even many universities, teach numpy as a part of their programming course. But many times, the users face, No Module Named Numpy Error. In this post, we’ll have a look at the causes and solutions for this error.
No Module Named Numpy is one of the persistent errors if you have multiple pythons installed or a virtual environment set up. This error mainly arises due to the unavailability of files in the Python site-packages. This error is easily solved by installing numpy in your working environment. But as installing numpy in the working environment is a tricky job, this error is one of the most irritating ones.
What is No Module Named Numpy?
Whenever an external module (numpy) is imported in python, it checks the package in the site packages folder if it’s available. If not, then ImportError No Module Named Numpy is raised. Moreover, if your local files in your directly have numpy.py, it can cause these issues too.
Although fixing this error requires a simple command to be used, it still can harass programmers if they are using a virtual environment. In the following section, we’ll learn about why this error is generated and the causes for it.
Why do I get No Module Named Numpy?
There are known reasons for the cause of this error. The most observed reason is due to the unavailability of Numpy in your working directory. But that’s not it, if your python file is named numpy.py, it can throw this error too. So the question arises –
Am I the only one facing this error?
No, thousands of programmers face this error either due to their IDE’s environment or they just haven’t installed Numpy.
Causes for No Module Named Numpy
As we mentioned earlier, there are some known causes for this No Module Named Numpy error to appear. Some of them are due to your mistake and some of them are not. Following are the most probable cause of this error –
Numpy Not Installed
Can you run games without installing them? No. Similarly, to use the numpy in your python program, you need to install it first. Numpy is not included in your build-in modules for python. As a result, you need to tell the package management system (pip) to install it!
Working on different Virtual Environment
Often, many different IDEs like Jupyter Notebook, Spyder, Anaconda, or PyCharm tend to install their own virtual environment of python to keep things clean and separated from your global python.
As a result, even if you have Numpy installed in your global python, you cannot use it in your virtual environment since it has separate package management. There are different methods to install numpy on each of these IDEs, all of them are mentioned in the next section.
Solutions for No Module Named Numpy
Following are the respective solutions according to your OS or IDEs for No Module Named Numpy error –
Installing modules can be tricky on Windows sometimes. Especially, when you have path-related issues. First of all, make sure that you have Python Added to your PATH (can be checked by entering
python in command prompt). Follow these steps to install numpy in Windows –
- Firstly, Open Command Prompt from the Start Menu.
- Enter the command
pip install numpyand press Enter.
- Wait for the installation to finish.
- Test the installation by using
import numpycommand in Python Shell.
Ubuntu or Linux or Mac
Generally, in Ubuntu, there are multiple versions of Python installed. This causes great confusion in installing Numpy. Check your version of python by entering the command
python --version in your terminal. Follow these steps to install numpy in Linux –
- Firstly, Open terminal in your Linux machine.
- Enter the command
pip install numpyin the terminal and hit Enter (Use pip3 if you have multiple pythons installed).
Anaconda installs its own conda environment to run python. This environment is separated from your outside installed python and can lead to import No Module Named Numpy errors. Usually, numpy is already installed in anaconda but to install numpy again in Anaconda –
- Open Anaconda Prompt from Start Menu.
- Enter the command
conda install numpyand Hit Enter.
- Wait for the setup to complete, and restart the Anaconda application once.
If you have installed Jupyter from the conda environment, it’ll use Anaconda’s virtual environment for the execution of python codes. Following is the way to install numpy in Jupyter Notebook –
- Open Anaconda Prompt and enter
conda install numpy.
- Restart Jupyter Notebook and Anaconda.
In VsCode, the Integrated Terminal uses the %PATH% of python.exe to run the python programs by default. As a result, if don’t have numpy installed in your python, it’ll throw ImportError No Module Named Numpy. Either you need to change the environment to Anaconda’s environment or install numpy on the default environment. The process to install numpy on the default environment is already mentioned in the above (Windows) section.
PyCharm has its own set of mini Anaconda environments. If numpy is missing in this environment, it’ll throw an error No Module Named Numpy. To install numpy in Pycharm –
- Firstly, Open Settings of Pycharm.
- Under Python Interpreter, press the Python Packages option.
- Search for numpy in the list and select install. If it’s already installed, check if it has an update available.
- Wait for its finishes and restarts your PyCharm once.
No Module Named Numpy Still Not Resolved?
Tried all the above methods and still import numpy not working? Then there might be some python related issues with your computer. But don’t be sad, we’ve got a universal solution for you!
Using Google Colab for your Python Projects will prevent you to install numpy on your system. Colab has its own powerful virtual environment with thousands of modules preinstalled and numpy is one of them. Follow these steps to use Google Colab for numpy –
- Firstly, log in to your Google Account.
- Head over to colab.research.google.com and start a new notebook.
- Test your program by running
Some Other Child Modules Error
Numpy has many other child libraries which can be installed externally. All of these libraries look like a part of numpy, but they need to be installed separately. Following are some of the examples –
No module named numpy.core._multiarray_umath
This error can be resolved by using p
ip install numpy --upgrade command and upgrading your numpy version. Other libraries like TensorFlow and scikit-learn depend on new APIs inside the module, that’s why your module needs to be updated.
No module named numpy.testing.nosetester
Run the following commands in your terminal to resolve this error –
pip install numpy==1.18 pip install scipy==1.1.0 pip install scikit-learn==0.21.3
No module named numpy.distutils._msvccompiler
Use Python version 3.7 to solve this error. The newer versions 3.8 and 3.9 are currently unsupported in some of the numpy methods.
Errors are part of a programmer’s life and they’ll never leave. Numpy has already blessed us with many powerful methods to easily handle data. But sometimes, we’ll get import errors and possibly other errors too. We’ve mentioned all possible solutions for the No Module Named Numpy in the post.