How To Solve “ModuleNotFoundError: No module named ‘scipy’” Error In Python

ModuleNotFoundError: No module named ‘scipy’ in Python

SciPy is a library built on top of the NumPy extension. SciPy provides functions for algebraic, integration, and statistical calculations. You want to try using it and start installing, but you get an error message: “ModuleNotFoundError: No module named ‘scipy’ in Python”. Here is the solution for you.

Why does the “ModuleNotFoundError: No module named ‘scipy'” error occur?

We get the “ModuleNotFoundError: No module named ‘scipy'” error message because we did not install the SciPy package on our machine.

Besides that, there are some other reasons as follows:

  • You work in a virtual environment but installed ‘scipy’ globally
  • You named your module ‘scipy’ so that the official ‘SciPy’ module will be overwritten.
  • You import ‘SciPy’ into your code, then accidentally name a variable as ‘scipy’. This action will make the import statement disabled.

The solution for this error

Assume that the pip module has been successfully installed on your machine. If you need help installing pip see the pip installation guide.

Fixing this error is very easy. You need to install the SciPy package on your computer precisely. But before doing this, I recommend you to check which version of python you are using.

Open the terminal and use this command:

python –-version

Output:

python 3.10.7

Then, install the SciPy package.

:: For Python 2. x version 
pip install scipy

:: For Python 3. x version 
pip3 install scipy

In some situations, you can edit the command as below, this command will help you to install ‘scipy’ in case pip does not exist in the PATH environment variables:

:: For Python 2. x version 
python -m pip install scipy

:: For Python 3. x version 
python3 -m pip install scipy

Now, let’s check if you have installed it successfully:

import scipy
print('SciPy version: {}'.format(scipy.__version__))

Output:

SciPy version: 1.9.1

So you have successfully installed the SciPy package. We have solved the “ModuleNotFoundError: No module named ‘scipy’” error.

The last thing I want to remind you is to pay attention to your variable and module names, don’t name them as ‘scipy’ to avoid errors.

Summary

In conclusion, I showed you how to install SciPy on your computer with a straightforward command to fix the error ModuleNotFoundError: No module named ‘scipy’ in Python . I hope the information above is helpful to you.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *