Python 安装 scipy 包后出现“ImportError: No module named scipy”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24619015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:53:43  来源:igfitidea点击:

"ImportError: No module named scipy" after installing the scipy package

pythonscipypipraspbian

提问by Philip R.

So I recently tried to install scipy on my Raspbian (Debian for Raspberry Pi) operating system using sudo pip install scipy. The command worked without too much trouble, and I can see the file located under pi/build/scipy.

所以我最近尝试在我的 Raspbian(Raspberry Pi 的 Debian)操作系统上使用sudo pip install scipy. 该命令运行起来没有太多麻烦,我可以看到位于pi/build/scipy.

However, when I actually try to import it in a python program, it gives me ImportError: No module named scipyI'm not really sure how to go about pointing the OS in the correct location to import the scipy module.

但是,当我实际尝试在 python 程序中导入它时,它让我ImportError: No module named scipy不确定如何将操作系统指向正确的位置以导入 scipy 模块。

采纳答案by Braiam

Unless you are inside the pip environment it won't work, at all. I would recommend you to install the python-scipypackage instead, which would assure you that will work:

除非您在 pip 环境中,否则它根本无法工作。我建议您改为安装该python-scipy软件包,这将确保您可以正常工作:

?  ~  sudo apt-get install python-scipy
Selecting previously unselected package python-decorator.
(Reading database ... 252269 files and directories currently installed.)
Preparing to unpack .../python-decorator_3.4.0-2_all.deb ...
Unpacking python-decorator (3.4.0-2) ...
Selecting previously unselected package python-scipy.
Preparing to unpack .../python-scipy_0.13.3-2+b1_i386.deb ...
Unpacking python-scipy (0.13.3-2+b1) ...
Setting up python-decorator (3.4.0-2) ...
Setting up python-scipy (0.13.3-2+b1) ...
?  ~  python
Python 2.7.7 (default, Jun  3 2014, 23:36:29) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> 

回答by chris-sc

I think you have a problem with the permissions after installing with sudo pip. (

我认为您在使用sudo pip. (

A quick solution to this problem could be to install scipy with

这个问题的一个快速解决方案可能是安装 scipy

sudo -i
pip install scipy

To get the sudo-install working you might need to change your default umask(umask 0022).

要使sudo-install 工作,您可能需要更改默认值umask( umask 0022)。