Solving Python Numpy ModuleNotFoundError: No module named ‘numpy.testing.nosetester’

Python Numpy ModuleNotFoundError: No module named ‘numpy.testing.nosetester’ is an error which occurs because of a scipy and numpy incompatibility issue.

Today, I will explain why this error takes place and how to fix it, while also presenting the steps in detail and adding other solutions that could solve the error.

Exploring Python Numpy ModuleNotFoundError: No module named ‘numpy.testing.nosetester’

This is an error which occurs because of a scipy and numpy incompatibility issue.

Bellow is the error message, please make sure it is the right one.

                                                                       #
ModuleNotFoundError: No module named 'numpy.testing.nosetester'
                                                                       #

Bellow we will take care of the error using a great method that has solved the problem for me.

The Method that solved my issue : Fix the compatibility issues by correctly importing numpy , scipy and the package you are importing from

There is a scipy and numpy incompatibility problem.

As of now, if you install a scipy version inferior to 0.19.0 ( for example if you install scipy version 0.18.0 ) and install numpy version 1.18.5 for example you will end up with this error.

numpy.testing.nosetester. is deprecated in the latest versions of numpy. Which causes the error.

I am going to give you some examples that will cause the error. Importing rundocs causes the error

                                                                       #
from numpy.testing import rundocs
                                                                       #

Importing shap will cause the error

                                                                       #
import shap
                                                                       #

Importing DecisionTreeClassifier will also cause the error

                                                                       #
from sklearn.tree import DecisionTreeClassifier
                                                                       #

The fix is to upgrade :

The package you are importing from.

Scipy and numpy

First, let us start by upgrading scipy and numpy. In this example I am going to install numpy version 1.18.5

                                                                       #
pip install numpy==1.18.5
                                                                       #

In this example I am going to install scipy==1.7.1

                                                                       #
pip install scipy==1.7.1
                                                                       #

Finally, I am going to upgrade scikit-learn to one of the most recent versions

                                                                       #
pip install scikit-learn==1.1.1
                                                                       #

If the whole process in this method does not work and you have python 3, you can try Try upgrading all package using pip3 and without specifying the exact versions you want.

                                                                       #
pip3 install -U numpy
pip3 install -U scipy
pip3 install -U scikit-learn
                                                                       #

You can also do the same with only pip

                                                                       #
pip install -U numpy
pip install -U scipy
pip install -U scikit-learn
                                                                       #

If that does not work, you can try to uninstall each package before installing it like this

                                                                       #
pip uninstall numpy
pip install -U numpy
pip uninstall scipy
pip install -U scipy
pip uninstall scikit-learn
pip install -U scikit-learn
                                                                       #

You can also do the same using pip3 , I hope this was helpful and you got rid of the error, thank you for reading this blog post to the end.

Summing-up : 

Here we are at the end of the road, at the end of this article, if you solved this error congrats, this was a confusing error for me the first time I encountered it.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/