While are you trying to import the ‘NumPy‘ module without installing the package or If you install it in an incorrect environment. Then you will face ModuleNotFoundError: No module named ‘numpy’, this error.
In this article, we will discuss about this ModuleNotFoundError: No module named ‘numpy’ error in Python. And how to resolve the error all the possible solutions with examples.
How to ModuleNotFoundError: No module named ‘numpy’ Error Occurs?
The Python error “ModuleNotFoundError: No module named ‘numpy’” occurs for multiple reasons:
- When have you installed pip install NumPy, there have not NumPy package.
- You have installed the NumPy package in a different Python version.
- If you are using the virtual environment and NumPy module is not installed in your virtual environment.
- Declaring a variable name numpy.
Import error: No module named numpy
How To Fix ModuleNotFoundError: No module named ‘numpy’ Error?
There are different ways to fix ModuleNotFoundError: No module named ‘numpy’ this error. Let us take a look at every solution.
- How To Fix ModuleNotFoundError: No module named ‘numpy’ Error?
For the solve ModuleNotFoundError: No module named ‘numpy’ Error First you have to install numpy module. So, opening your terminal in your project’s root directory then run this command: pip install numpy. Now, I hope your error will be solved.
- ModuleNotFoundError: No module named ‘numpy’
For the solve ModuleNotFoundError: No module named ‘numpy’ Error uninstall the numpy package then reinstall numpy. Now, I hope your error will be gone.
Solution 1: Installing the NumPy module
First of all open your terminal in your project’s root directory then run this command.
# 👇️ in a virtual environment or using Python 2
pip install numpy
# 👇️ for python 3
pip3 install numpy
# 👇️ if you get permissions error
sudo pip3 install numpy
# 👇️ if you don't have pip in your PATH environment variable
python -m pip install numpy
# 👇️ for python 3
python3 -m pip install numpy
# 👇️ If you are installing it in Anaconda
conda install -c anaconda numpy
Solution 2: Installing NumPy inside the virtual environment
You have to create a virtual environment if you don’t have one.
# 👇️ For python3 Create a virtual Environment
python3 -m venv venv
Now Activate the virtual environment.
# 👇️ Activate the virtual environment (windows command)
venv\Scripts\activate.bat
# 👇️ Activate the virtual environment (windows powershell)
venv\Scripts\Activate.ps1
Activate the virtual environment On Linux.
source venv/bin/activate
Now Install lxml inside the virtual environment below the command.
pip install PyJWT
Solution 3: module name is not declared name a variable name
You should check if you haven’t named a module in your project as numpy.py as it may shadow the original numpy module.
You shouldn’t be declaring a variable named numpy as that would also shadow the original module.
Solution 4: Uninstall the NumPy
package
# 👇️ check if you have PyJWT installed
pip3 show numpy
# 👇️ uninstall numpy
pip3 uninstall numpy
# 👇️ install numpy
pip3 install numpy
Now, I hope your error will be solved.
Conclusion
In this article, we have discussed what causes the error and we have discussed ways to fix the error.
we hope this article has been informative. Thank you for reading. Kindly comment and let us know if you found it helpful.