I keep getting the "NameError: name 'scipy' is not defined", when I know I've downloaded and imported scipy.
Any tips?
Here's my code:
import scipy.integrate as integrate
exact = scipy.integrate.ode(eq1)
print(exact)Thanks!!
43 Answers
try with
import scipy.integrate as integrate
exact = integrate.ode(eq1) #notice, no scipy
print(exact)the problem is that you import the module scipy.integrate and bound it to the variable integrate with the instruction as, that is why you get the name error in scipy.integrate.ode(eq1), scipy is not in your namespace, just integrate;
if you want to include scipy it then import it as
import scipyso you can use its other features
import scipy.integrate as integrate
import scipy
exact = integrate.ode(eq1)
print(exact)or just without the as
import scipy.integrate
exact = scipy.integrate.ode(eq1)
print(exact) 1 Import scipy and use its methods using dot operator.
import scipy
Sometimes it occurs when we missed installing scipy. You can install it using the following command:
pip install scipyAfter successful installation you can import it as follows:
import scipy