Skip to content Skip to sidebar Skip to footer

Importerror: No Module Named Scipy.sparse

I installed Scipy on Ubuntu using the following commands: sudo apt-get install python-scipy pip install scipy but when run import, I get this error: ImportError: No module named s

Solution 1:

scipy path mixed up. Uninstall

pip uninstall scipy

Install using conda worked for me

conda install scipy

Solution 2:

In Ubuntu 18.04 and later you could install Scipy and Keras for Python 3 with sudo apt install python3-scipy python3-keras and you'd be good to go, however you are using Ubuntu 16.04 and you installed Scipy for Python 2 which is not compatible with TensorFlow for Python 3.4, 3.5 and 3.6, so install the default Scipy package for Python 3 instead with this command:

sudo apt install python3-scipy  

For further instructions on installing TensorFlow in Ubuntu read this answer. It's worth reading because you are going to have to check for package version compatibility when working with TensorFlow from now on.

The command pip install scipy is not correct either if the purpose of that command was to upgrade Scipy. The correct command to upgrade Scipy would have been pip install --upgrade --user scipy and even so it would have been useless because your scipy that is currently installed is only for Python 2 and your TensorFlow is for Python 3.

Solution 3:

You are using Python 3, but with pip you install scipy for Python 2. Use:

pip3 install scipy  

or:

sudo apt install python3-scipy

Solution 4:

try

pip3 install scipy

and to install pip3

sudo python3 get-pip.py

Solution 5:

Just to make sure on which Python version you've installed Scipy try in the terminal:

which Python

Then try:

pip freeze 

to get a list of all the installed packages.

Maybe you have more than one python version and have installed the package to one and trying to execute your code using the other.

Post a Comment for "Importerror: No Module Named Scipy.sparse"