I have a file which imports a function from another file, like shown below.
file1.py:
# import scipy.signal
import file2
file2.foo()
file2.py:
import scipy
def foo():
scipy.signal.butter(2, 0.01, 'lowpass', analog=False)
When I run file1.py I get the following error:
File "file2.py", line 5, in foo scipy.signal.butter(2, 0.01, 'lowpass', analog=False) AttributeError: module 'scipy' has no attribute 'signal'
However, when I uncomment line 1 from file1.py (import scipy.signal) the error disappears. Why is this happening?
With scipy, you need to import the submodule directly with either import scipy.signal or from scipy import signal. Many submodule won't work if you just import scipy. You can read about the scipy api here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With