导入错误:没有名为scipy的模块

117 投票
17 回答
511878 浏览
提问于 2025-04-18 13:43

我正在使用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.

我该怎么办呢?

17 个回答

6

如果你想在Windows上把 scipy 安装到你的Python环境中,可以在这里找到 *.whl 文件:

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

记得在安装 scipy 之前,先安装 numpy+mkl

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

下载好正确的 *.whl 文件后,打开命令提示符,进入下载的文件夹,然后运行 pip install *.whl 来安装。

8

我之前也遇到过同样的问题,因为我同时安装了python2.7和python3。当我用python3运行程序时,也出现了同样的错误。后来我用这个命令安装了scipy,问题就解决了:

sudo apt-get install python3-scipy
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
29

为了确保你能轻松正确地安装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
178

试着用pip把它安装成一个Python包。你说你已经试过了:

sudo apt-get install python-scipy

现在运行:

pip install scipy

我在我的Debian系统上都试过了,结果都成功了。

撰写回答