Inqa
Inqa

Reputation: 55

Strange NameError: name 'math' is not defined, while "import math"

I receive NameError while executing this code. It is weird because there is import math in the code. There is import math in sigma module...Maybe it is kind of a conflict? Thanks for your time!

  File "C:\Users\Greenman\Documents\Python Scripts\sigma_crit.py", line 21, in sigma_crit
    # Simplified MC

NameError: name 'math' is not defined

import sigma as sgm # Module sigma has "import math" as well
import math
def sigma_crit(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, No):
    """
    Return value of critical stress calculated for one of three failure criterias.
    No: 1 - Simplified Mohr-Coulomb
        2 - Mohr-Coulomb
        3 - Drucker-Prager
        4 - list with 3 model's resutls
    sigmaX - stress at X wellbore axis
    sigmaY - stress at Y wellbore axis
    Theta - azimuth,anticlokwise from SH_max
    nu - Poisson's ratio
    alpha - Biot's  coefficient
    """ 
    sigma_theta = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, 1)
    sigma_zi = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha, 2)
    sigma_thzi = sgm.sigma_calc(sigmaX, sigmaY, sigmaZ, Theta, Pw, Pres, nu, alpha,3)
    # Conerting degrees to radians for below equations...Caution above functions has built-in converter
    Theta = math.radians(Theta)
    # Simplified MC

Upvotes: 2

Views: 7511

Answers (2)

YAN BINGXIN
YAN BINGXIN

Reputation: 11

The same error occurs to me, and the following operation works for me:

change

import math

to

from math import sqrt, ceil

So I think you can separately import the function you want to use from math.

Upvotes: -1

Martijn Pieters
Martijn Pieters

Reputation: 1123400

You are running stale bytecode. You changed the source file but did not restart Python.

You can see this from the traceback; the traceback is generated by reading the source file and taking embedded line number information from the bytecode being run to show the corresponding line in the source.

But your traceback shows the comment on the next line; the bytecode reference is clearly outdated and you altered the code since.

Upvotes: 4

Related Questions