Python AttributeError: 'module' object (scipy) has no attribute *** 为什么会出现这个错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18049687/
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
AttributeError: 'module' object (scipy) has no attribute *** Why does this error occur?
提问by Sibbs Gambling
In scipy, the error occurs quite often.
在 scipy 中,错误经常发生。
>>> import scipy
>>> scipy.integrate.trapz(gyroSeries, timeSeries)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'integrate'
>>>
I figure out how to solve this problem by doing the following:
我通过执行以下操作来弄清楚如何解决这个问题:
>>>
>>> import scipy.integrate
>>> scipy.integrate.trapz(gyroSeries, timeSeries)
>>> 1.2
My question:
我的问题:
Why does the error occur?
为什么会出现错误?
Why would that fix the error?
为什么会修复错误?
采纳答案by Amit
Most possibly because scipy is a library (package) that contains modules and to import a specific module from the scipy library, you need to specify it and import the module itself. As it's a separate module (sub-package), once you import it, it's attributes are available to you by using the regular scipy.module.attribute
很可能是因为 scipy 是一个包含模块的库(包),要从 scipy 库中导入特定模块,您需要指定它并导入模块本身。因为它是一个单独的模块(子包),一旦你导入它,它的属性就可以通过使用常规的 scipy.module.attribute
回答by Employee
In order to fix the error, add the following line at the top of your script
为了修复错误,请在脚本顶部添加以下行
from scipy import integrate