ImportError: No module named scipy(已经解决)

背景:在ubuntu14或Ubuntu16中默认使用的python2.7的,由于系统依赖于它,就不好卸载了(曾经尝试卸载过,后来系统起不来了)。有时使用python2.7执行一些脚本。

在使用Python 2.7,但是即使安装了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

已经使用此apt-get命令安装了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.

解决方案

pip install scipy

报了权限问题;

于是执行如下命令:

pip install scipy  --user

成功安装,nice!

如果使用用python3的朋友,可以执行命令:pip3 install scipy  --user

坑(本人跳进去了)

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

这个思路是没错的,但是在安装pip时会有问题,虽然能安装最新的pip版本(如pip 19),但是pip的版本真的合适当前python的版本吗,比如用ubuntu14自带的python2.7就会有问题了。



希望对你有帮助。

发布了178 篇原创文章 · 获赞 373 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/qq_41204464/article/details/103575669
今日推荐