不能使用scipy.stats

时间:2014-02-28 23:51:51

标签: python-2.7 scipy

使用scipy.stats时出错。在导入scipy后的脚本中。

AttributeError: 'module' object has no attribute 'stats'

在脚本编辑器中,我可以在输入scipy后点击统计数据。从下拉菜单中, 在python控制台中我无法从下拉菜单中选择python.stats,它不在那里。 我正在使用pandas 2.7和SciPy 0.13.0 这是为什么? 任何已知的问题?

1 个答案:

答案 0 :(得分:9)

扩展我的评论(列出答案)。

Scipy和许多其他大型软件包一样,不会自动导入所有模块。如果我们想使用scipy的子包,那么我们需要直接导入它们。

但是,一些scipy子包加载了其他scipy子包,因此例如导入scipy.stats也会导入大量其他包。但我从不依赖它来在命名空间中提供子包。

在许多使用scipy的软件包中,首选模式是导入子包以使其名称可用,例如:

>>> from scipy import stats, optimize, interpolate


>>> import scipy
>>> scipy.stats
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'stats'
>>> scipy.optimize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'optimize'

>>> import scipy.stats
>>> scipy.optimize
<module 'scipy.optimize' from 'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'>