ModuleNotFoundError: No module named ‘scipy’

Are you getting the error “modulenotfounderror no module named ‘scipy’“? Yes, you have come to the right place. In this tutorial, I will show you how to solve the error “no module named ‘scipy’“.

The error “modulenotfounderror: no module named scipy” occurs when we forget to install the “scipy” module or install it in the wrong environment.

[Solution] modulenotfounderror: no module named scipy

To solve this error, you need to install the scipy Python package using the pip install scipy command.

Here is the command to install scipy in your system:

# If you are in a virtual environment or using Python 2
pip install scipy

# For python 3, could also be pip3.10
pip3 install scipy

# If you get permissions error you can run command as admin
sudo pip3 install scipy
pip install scipy --user

# If you don't have pip in your PATH environment variable
python -m pip install scipy

# For python 3 if you don't have pip in your PATH environment variable
python3 -m pip install scipy

# Using py alias (Only works for Windows)
py -m pip install scipy

# If you are coding with Anaconda
conda install -c anaconda scipy

# If you are using Jupyter Notebook
!pip install scipy

When you successfully install scipy, you can import it like this:

from scipy import stats
from scipy.stats import norm

print(dir(stats))
print('bounds of distribution lower: %s, upper: %s' % norm.support())

If your problem is still not resolved, you need to upgrade your PIP version. You can upgrade pip using the below commands according to your OS requirements.

# if you have pip already installed
pip install --upgrade pip

# if your pip is aliased as pip3 (Python 3)
pip3 install --upgrade pip

# if you don't have pip in your PATH environment variable
python -m pip install --upgrade pip

# if you don't have pip in your PATH environment variable
python3 -m pip install --upgrade pip

# if you have easy_install
easy_install --upgrade pip

# if you get a permissions error
sudo easy_install --upgrade pip

# if you get a permissions error
pip install --upgrade pip --user

# upgrade pip for the current user
python -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip

# Installing pip directly from get-pip.py (MacOS and Linux)
curl https://bootstrap.pypa.io/get-pip.py | python

# if you get permissions issues you can use this command
curl https://bootstrap.pypa.io/get-pip.py | sudo python

# alternative for Ubuntu/Debian
sudo apt-get update && apt-get upgrade python-pip

# alternative for Red Hat / CentOS / Fedora
sudo yum install epel-release
sudo yum install python-pip
sudo yum update python-pip

When you upgrade the PIP, you also need to upgrade ‘setuptools‘ and ‘wheels‘. You can update these packages by using these commands.

[Fixed]: Export ‘Switch’ (imported as ‘Switch’) was not found in ‘react-router-dom’

pip install --upgrade setuptools wheel

pip3 install --upgrade setuptools wheel

python3 -m pip install --upgrade setuptools wheel

The Python error “modulenotfounderror no module named ‘scipy’” can occur for multiple reasons:

  1. Not having scipy package installed. If you have not installed the scipy package then you can install it with this command “pip install scipy”.
  2. Installing the scipy package in a different python version than you are using.
  3. Installing the package in the global environment when you are using the virtual environment.
  4. You are using the incorrect version of python on your IDE. (e.g. VS Code)
  5. Using the file name “scipy.py”. If you are using a name like this scipy.py then consider it change to something else.
  6. Declaring a variable with the name “scipy”. If you have a variable scipy change its name to something else.

Conclusion on “modulenotfounderror: no module named scipy

Programmers, we discussed the Python error “modulenotfounderror no module named ‘scipy’“. I hope you have solved your Python error. If you have any questions about the tutorial or are still facing the error, please let us know in the comments section.

Leave a Reply