AttributeError: 'module' object (scipy) has no attribute *** Why does this error occur?

46,322

Solution 1

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

Solution 2

In order to fix the error, add the following line at the top of your script

from scipy import integrate

Solution 3

Just simply use

import scipy.constants as spc

and then

C   = spc.c #speed of light m/s
pi  = spc.pi
Share:
46,322

Related videos on Youtube

Sibbs Gambling
Author by

Sibbs Gambling

Updated on December 13, 2021

Comments

  • Sibbs Gambling
    Sibbs Gambling over 2 years

    In scipy, the error occurs quite often.

    >>> 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?