导入错误:找不到名为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个回答

2

我的问题是在使用pip3安装时,我拼错了一个库的名称,导致同一条命令中下载的其他库没有被安装。只需要再次运行pip3 install就可以从缓存中重新安装它们。


最好复制命令而不是手动输入,因为如果您拼错了命令,可能会导致安装恶意库/软件包或其他相关错误。要非常小心避免Typosquatting和Supply Chains漏洞。 - Shedrack

2

你的Python不知道你安装了Scipy的位置。将Scipy路径添加到PYTHONPATH中,我希望它能解决你的问题。


嗨,非常感谢,但你能给我执行该操作的命令吗?我是Linux新手。 - ihmpall
1
如果您正在使用bash,则可以在bash配置文件中添加以下行:export PYTHONPATH="/path/to/scipy:$PYTHONPATH" - RealityPC

1

在@user5747799之前的步骤中,它不能直接工作,而是改变了URL(https://bootstrap.pypa.io/pip/2.7/get-pip.py),现在在Ubuntu 20.04上spicy工作得非常好。

此外,我按照以下步骤在Python 2和3版本之间进行切换:https://www.fosslinux.com/39384/switching-between-python-2-and-3-versions-on-ubuntu-20-04.htm

使用备用URL安装pip:

$ 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

为了验证
$ python

那么

>>> import scipy

没有错误显示。


1

尝试强制重新安装scipy:

python3 -m pip install scipy --force-reinstall

1
使用 sudo pip install scipy 命令来安装这个库,这样它就不会在后面请求权限了。

0

对于Mac系统,请运行以下命令来安装scipy

$ brew install scipy
$ pip install scipy

0

用于Python3安装scipy的命令如下

python3 -m pip install scipy

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