简体   繁体   English

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

[英]No module named scipy.stats - Why despite scipy being installed

How to use python and scipy to get a poissio random variable? 如何使用python和scipy来获得一个poissio随机变量? Wow..I installed scipy and per the docs I get No module named scipy.stats? 哇..我安装scipy并根据文档我得到没有模块名为scipy.stats? I am on ubuntu 12.04. 我在ubuntu 12.04。 So......go figure 所以......去看看

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

I think scipy is the way to go. 我认为scipy是要走的路。 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 因为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

I accidentally caused this issue by naming one of my scipy test programs "scipy.py". 我通过命名我的一个scipy测试程序“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: 当然,这使得此目录中的任何“import scipy”导入我的测试程序而不是系统库,从而导致许多错误,例如:

ImportError: No module named stats

It's embarrassing how long it took me to figure this out! 令人尴尬的是我花了多长时间搞清楚这一点!

Not sure exactly what the install issue is, perhaps consider installing Enthought Canopy or EPD ? 不确定安装问题究竟是什么,或许可以考虑安装Enthought Canopy或EPD It handles all of the packages and dependencies nicely. 它很好地处理所有包和依赖项。

Alternatively, if you just want to do some stats, try installing statsmodels . 或者,如果您只想做一些统计数据,请尝试安装statsmodels

I had a similar issue with Python 3.4 on my Windows 7 machine. 我在Windows 7机器上遇到了与Python 3.4类似的问题。 I had to update my scipy package 'pip install --upgrade scipy' 我不得不更新我的scipy包'pip install --upgrade scipy'

pip install --upgrade --force-reinstall scipy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM