不能使用 scipy.stats [英] Cannot use scipy.stats
问题描述
在使用 scipy.stats 时出现错误.在导入 scipy 后的脚本中.
AttributeError: 'module' 对象没有属性 'stats'
在脚本编辑器中,我可以在输入 scipy 后单击统计信息.从下拉菜单中,在 python 控制台中,我无法从下拉菜单中选择 python.stats,它不存在.我正在使用 Pandas 2.7 和 SciPy 0.13.0这是为什么?有任何已知问题吗?
扩展我的评论(列出答案).
Scipy 与许多其他大型软件包一样,不会自动导入所有模块.如果要使用scipy的子包,则需要直接导入.
但是,一些 scipy 子包会加载其他 scipy 子包,因此例如导入 scipy.stats 也会导入大量其他包.但是我从不依赖这个来在命名空间中提供子包.
在许多使用 scipy 的包中,首选模式是导入子包以使其按名称可用,例如:
<预><代码>>>>从 scipy 导入统计信息,优化,插值>>>进口scipy>>>scipy.stats回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>AttributeError: 'module' 对象没有属性 'stats'>>>scipy.optimize回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>AttributeError: 'module' 对象没有属性 'optimize'>>>导入 scipy.stats>>>scipy.optimize<来自'C:\Python26\lib\site-packages\scipy\optimize\__init__.pyc'的模块'scipy.optimize'>I get an errr when using scipy.stats. in a script after importing scipy.
AttributeError: 'module' object has no attribute 'stats'
Within script editor I can click on stats after typing scipy. from the pulldown menu, within python console I can not select python.stats from the pulldown menu, it's not there. I'm using pandas 2.7 and SciPy 0.13.0 Why is that? Any known issues?
expanding on my comment (to have a listed answer).
Scipy, as many other large packages, doesn't import all modules automatically. If we want to use the subpackages of scipy, then we need to import them directly.
However, some scipy subpackages load other scipy subpackages, so for example importing scipy.stats also imports a large number of the other packages. But I never rely on this to have the subpackage available in the namespace.
In many packages that use scipy, the preferred pattern is to import the subpackages to have them available by their names, for example:
>>> 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'>
这篇关于不能使用 scipy.stats的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!