导入错误:找不到名为scipy的模块。

115

我正在使用Python 2.7并尝试让PyBrain工作。

但是即使已经安装了scipy,我仍然遇到了这个错误 -

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

我使用以下命令安装了scipy -

sudo apt-get install python-scipy

我获取 -

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.

我该怎么做?


python -c 'import scipy; print(scipy)'which pythonpython -c 'import sys; print(sys.path) - Fred Foo
追溯(Traceback)最近的一次调用: 文件“<string>”,第1行,在<module>中 导入错误(ImportError):没有名为scipy的模块,且其Python版本为2.7.5。 - ihmpall
有没有不需要使用sudo的解决方案? - Charlie Parker
对于Windows用户 - Martin Thoma
17个回答

176
尝试使用pip将其安装为Python包。您说您已经尝试过:
sudo apt-get install python-scipy

现在运行:

pip install scipy

我两个都运行了,在我的基于Debian的计算机上都可以运行。


我不能使用sudo...还有其他解决方案吗?我不明白问题出在哪里,以及为什么那样解决了问题? - Charlie Parker
6
如果你使用的是Python 3,那么你需要使用相应的名称:python3-scipypip3 - Alexis Wilke
  1. 重新安装Scipy。
  2. 关闭并重新打开Jupyter服务器。 这对我有用。谢谢。
- Gopal Kalpande
你不需要同时安装Debian包和Python包。除非它已经过时,否则我会更倾向于使用发行版的包。 - Lucas

28
为了确保 Python 的简单和正确安装,请从一开始就使用 pip。
安装 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

使用pip安装scipy:

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

10

对于Windows用户:

经过几天的探索,我找到了这个解决方案。首先,您要安装哪个版本的Python?

如果你想安装Python 2.7版本:

步骤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

如果你想安装Python 3.4版本:

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

如果你想安装Python 3.5版本:

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

如果你想安装Python 3.6版本:

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

链接:[点击查看][1]

安装完成后,转到您的目录。

例如,我的目录:

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

步骤2:

Numpy+MKL

从相同的网站上根据python版本再次获取:

之后再次在脚本文件夹中使用相同的内容。

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

在Python文件夹中进行测试。

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

2
谢谢,这对我很有用。为了节省时间,我们可以在这里找到这些轮子 http://www.silx.org/pub/wheelhouse/ :) - Raviraj Subramanian

8

我曾经遇到过同样的问题,因为我同时安装了python2.7和python3。当我使用python3运行程序时,我收到了同样的错误信息。 我使用以下命令安装scipy,问题已得到解决:

sudo apt-get install python3-scipy

6
如果您正在使用PyCharm,请转到设置,然后在项目解释器子选项卡中单击列表旁边的“+”符号,在其中的搜索栏中搜索名称“scipy”,并安装该软件包。

scipy


对我来说非常有效。谢谢(Python v:3.10) - hollyjolly

6

5

For Windows User : pip install -U scipy


4
尝试使用pip将其作为Python包安装,步骤如下:
$ sudo apt-get install python-scipy

如果您想运行Python 3.x脚本,请按照以下方式安装Scipy:

$ pip3 install scipy
Otherwise install it by:
$ pip install scipy

4
我建议您通过以下方式删除scipy:
apt-get purge scipy

接着通过安装它来完成

pip install scipy

如果两者同时进行,可能会因版本不同而混淆deb软件包管理器。

3
这可能太基础(也许是可以预期的),但是 -
Fedora用户可以使用:
sudo dnf install python-scipy
然后(对于python3.x): pip3 install scipy
或(对于python2.7): pip2 install scipy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接