ImportError: No module named scipy
Asked Answered
J

17

117

I am using Python 2.7 and trying to get PyBrain to work.

But I get this error even though scipy is installed -

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-
py2.7.egg/pybrain/__init__.py", line 1, in <module>
    from pybrain.structure.__init__ import *
  File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/__init__.py", line 1, in <module>
    from pybrain.structure.connections.__init__ import *
  File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/connections/__init__.py", line 1, in <module>
    from pybrain.structure.connections.full import FullConnection
  File "/usr/local/lib/python2.7/site-packages/PyBrain-0.3.1-py2.7.egg/pybrain/structure/connections/full.py", line 3, in <module>
    from scipy import reshape, dot, outer
ImportError: No module named scipy

I have installed scipy using this command -

sudo apt-get install python-scipy

I get -

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-scipy is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

What should I do?

Jambalaya answered 17/7, 2014 at 15:44 Comment(4)
python -c 'import scipy; print(scipy)'? which python? python -c 'import sys; print(sys.path)?Nagle
Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named scipy and its python 2.7.5Jambalaya
is there a solution without sudo?Horseman
For Windows usersFrail
T
178

Try to install it as a python package using pip. You said you already tried:

sudo apt-get install python-scipy

Now run:

pip install scipy

I ran both and it worked on my Debian-based box.

Tryptophan answered 19/1, 2015 at 1:44 Comment(4)
I can't sudo...is there another solution? I don't understand what was the issue and why did that solve the problem?Horseman
@DragonSpit If you have python 3, then you need use the corresponding names: python3-scipy and pip3.Chaddie
1. reinstall scipy 2. shutdown and reopen jupyter server. It worked for me. Thank youViaticum
You should not need to install both the Debian package and the Python package. I would favor the Distribution package unless it is out of date.Zadazadack
H
29

To ensure easy and correct installation for python use pip from the get go

To install pip:

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python2 get-pip.py   # for python 2.7
$ sudo python3 get-pip.py   # for python 3.x

To install scipy using pip:

$ pip2 install scipy    # for python 2.7
$ pip3 install scipy    # for python 3.x
Holliholliday answered 6/6, 2016 at 2:58 Comment(0)
L
10

For windows users:

I found this solution after days. Firstly which python version you want to install?

If you want for Python 2.7 version:

STEP 1:

scipy‑0.19.0‑cp27‑cp27m‑win32.whl

scipy‑0.19.0‑cp27‑cp27m‑win_amd64.whl

numpy‑1.11.3+mkl‑cp27‑cp27m‑win32.whl

numpy‑1.11.3+mkl‑cp27‑cp27m‑win_amd64.whl

If you want for Python 3.4 version:

scipy‑0.19.0‑cp34‑cp34m‑win32.whl

scipy‑0.19.0‑cp34‑cp34m‑win_amd64.whl

numpy‑1.11.3+mkl‑cp34‑cp34m‑win32.whl

numpy‑1.11.3+mkl‑cp34‑cp34m‑win_amd64.whl

If you want for Python 3.5 version:

scipy‑0.19.0‑cp35‑cp35m‑win32.whl

scipy‑0.19.0‑cp35‑cp35m‑win_amd64.whl

numpy‑1.11.3+mkl‑cp35‑cp35m‑win32.whl

numpy‑1.11.3+mkl‑cp35‑cp35m‑win_amd64.whl

If you want for Python 3.6 version:

scipy‑0.19.0‑cp36‑cp36m‑win32.whl

scipy‑0.19.0‑cp36‑cp36m‑win_amd64.whl

numpy‑1.11.3+mkl‑cp36‑cp36m‑win32.whl

numpy‑1.11.3+mkl‑cp36‑cp36m‑win_amd64.whl

Link: [click[1]

Once finish installation, go to your directory.

For example my directory:

cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip install [where/is/your/downloaded/scipy_whl.]

STEP 2:

Numpy+MKL

From same web site based on python version again:

After that use same thing again in Script folder

cd C:\Users\asus\AppData\Local\Programs\Python\Python35\Scripts>
pip3 install [where/is/your/downloaded/numpy_whl.]

And test it in python folder.

Python35>python 
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. 
>>>import scipy
Lockout answered 15/6, 2017 at 12:55 Comment(1)
Thanks, It worked for me. To save some time, we can find these wheels in here silx.org/pub/wheelhouse :)Finochio
K
8

I had a same problem because I installed both of python2.7 and python3. when I run program with python3 I received same error. I install scipy with this command and problem has been solved:

sudo apt-get install python3-scipy
Koons answered 3/1, 2018 at 9:5 Comment(0)
S
6

If you need to get scipy in your Python environment on Windows you can get the *.whl files here:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy

Remember that you need to install numpy+mkl before you can install scipy.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

When you have downloaded the correct *.whl files just open a command prompt in the download directory and run pip install *.whl.

Stockroom answered 27/7, 2016 at 21:20 Comment(0)
M
6

if you are using pycharm go to settings and in project interpreter sub-tab click on "+" sign next to list and in the search bar in there search name "scipy" and install the package.

scipy

Moneymaker answered 16/7, 2018 at 15:34 Comment(1)
worked very well for me. Thank you (python v:3.10)Pilliwinks
G
5

For Windows User : pip install -U scipy

Grassland answered 7/11, 2017 at 13:6 Comment(0)
C
4

I recommend you to remove scipy via

apt-get purge scipy

and then to install it by

pip install scipy

If you do both then you might confuse you deb package manager due to possibly differing versions.

Cuculiform answered 6/7, 2015 at 11:18 Comment(0)
R
4

Try to install it as a python package using pip as follows

$ sudo apt-get install python-scipy

If you want to run a python 3.x script, install scipy by:

$ pip3 install scipy
Otherwise install it by:
$ pip install scipy
Rutherford answered 3/7, 2017 at 1:18 Comment(0)
M
3

This may be too basic (and perhaps assumable), but -

Fedora users can use:

sudo dnf install python-scipy

and then (For python3.x):

pip3 install scipy

or (For python2.7):

pip2 install scipy

Matney answered 14/11, 2018 at 21:8 Comment(0)
M
2

Your python don't know where you installed scipy. add the scipy path to PYTHONPATH and I hope it will solve your problem.

Mills answered 17/7, 2014 at 15:57 Comment(2)
Hi.Thanks a ton but can you give me the command to do that?Linux newbie,Jambalaya
If you are using bash, in your bash profile file, you can add this line export PYTHONPATH="/path/to/scipy:$PYTHONPATH"Mills
D
2

My problem was that I spelt one of the libraries wrongly when installing with pip3, which ended up all the other downloaded libaries in the same command not being installed. Just run pip3 install on them again and they should be installed from their cache.

Dismuke answered 1/9, 2017 at 16:42 Comment(1)
It is better to copy the command instead of typing it, this may lead to the installation of malicious libraries/packages or some other associated errors if you misspelled a command. Better be very careful from Typosquatting and Supply Chains Vulnerabilities.Jollenta
J
1

Use sudo pip install scipy to install the library so It cannot ask for permissions later

Jollenta answered 2/1, 2021 at 19:1 Comment(0)
E
1

in previous steps by @user5747799, it do not work directly but instead change the URL (https://bootstrap.pypa.io/pip/2.7/get-pip.py) and now spicy work very well on Ubuntu 20.04

Also o follow steps to switch between version from https://www.fosslinux.com/39384/switching-between-python-2-and-3-versions-on-ubuntu-20-04.htm

To install pip using alternative URL:

$ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
$ sudo python2 get-pip.py.2   # for python 2.7 (or verify the result of previous step)
$ sudo python3 get-pip.py   # for python 3.x

To install scipy using pip:

$ pip2 install scipy    # for python 2.7
$ pip3 install scipy    # for python 3.x

in order to verify

$ python

then

>>> import scipy

with no errors to show.

Episcopalism answered 26/11, 2021 at 16:55 Comment(0)
S
1

Try forcing a reinstall of scipy:

python3 -m pip install scipy --force-reinstall
Sublunary answered 31/1, 2023 at 18:39 Comment(0)
C
0

for Mac run below command to install scipy

$ brew install scipy
$ pip install scipy
Creel answered 4/2, 2022 at 20:47 Comment(0)
B
0

for python3 below command to install scipy

python3 -m pip install scipy
Blether answered 31/1, 2023 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.