Nameerror: Name 'Scipy' Is Not Defined

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

4

3 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 scipy

so 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 scipy

After successful installation you can import it as follows:

import scipy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest