背景:在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就會有問題了。
希望對你有幫助。