python Error

Python3 NameError: name 'math' is not defined

In the Python programming language, the "NameError: name 'math' is not defined" error may occur. This article introduces how to handle and resolve this error.

Shou Arisaka
1 min read
Oct 21, 2025

In the Python programming language, the “NameError: name ‘math’ is not defined” error may occur. This article introduces how to handle and resolve this error.

Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> math.pi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'math' is not defined

Solution

You need to import the module

from math import *

Image

Python : name ‘math’ is not defined Error? - Stack Overflow

Share this article

Shou Arisaka Oct 21, 2025

🔗 Copy Links