Python 没有名为 scipy.stats 的模块 - 为什么尽管安装了 scipy

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19261077/
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 13:17:01  来源:igfitidea点击:

No module named scipy.stats - Why despite scipy being installed

pythonscipy

提问by Tampa

How to use python and scipy to get a poissio random variable? Wow..I installed scipy and per the docs I get No module named scipy.stats? I am on ubuntu 12.04. So......go figure

如何使用 python 和 scipy 获取泊西奥随机变量?哇..我安装了 scipy 并且根据我得到的文档没有名为 scipy.stats 的模块?我在 ubuntu 12.04 上。所以……去图

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html

ubuntu@ubuntu:~/Downloads$ 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 482 not upgraded.
ubuntu@ubuntu:~/Downloads$ python
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy.stats import poisson
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named scipy.stats

采纳答案by Paul

I think scipy is the way to go. Probably you have a simple namespace visibility problem. since stats is itself a module you first need to import it, then you can use functions from scipy.stats

我认为 scipy 是要走的路。您可能有一个简单的命名空间可见性问题。由于 stats 本身就是一个模块,您首先需要导入它,然后您可以使用 scipy.stats 中的函数

import scipy
import scipy.stats
#now you can use
scipy.stats.poisson
#if you want it more accessible you could do what you did above
from scipy.stats import poisson
#then call poisson directly
poisson

回答by Josha Inglis

Not sure exactly what the install issue is, perhaps consider installing Enthought Canopy or EPD? It handles all of the packages and dependencies nicely.

不确定安装问题到底是什么,也许考虑安装Enthought Canopy 或 EPD?它可以很好地处理所有包和依赖项。

Alternatively, if you just want to do some stats, try installing statsmodels.

或者,如果您只想做一些统计,请尝试安装statsmodels

回答by djm457

I had a similar issue with Python 3.4 on my Windows 7 machine. I had to update my scipy package 'pip install --upgrade scipy'

我的 Windows 7 机器上的 Python 3.4 也有类似的问题。我不得不更新我的 scipy 包“pip install --upgrade scipy”

回答by Orion Lawlor

I accidentally caused this issue by naming one of my scipy test programs "scipy.py". Of course, this makes any "import scipy" in this directory import my test program, not the system library, in turn resulting in lots of errors like:

我不小心将我的 scipy 测试程序之一命名为“scipy.py”导致了这个问题。当然,这会使此目录中的任何“import scipy”导入我的测试程序,而不是系统库,从而导致许多错误,例如:

ImportError: No module named stats

It's embarrassing how long it took me to figure this out!

尴尬的是我花了多长时间才弄明白!

回答by Apoorva Malemath

pip install --upgrade --force-reinstall scipy

pip install --upgrade --force-reinstall scipy