1

for some reason I'm getting an error when I try to import pi in my code. For example, I'll create a file in Text Wrangler with the following code:

from math import pi

print(pi * 2)

When I run the code in Terminal, I get the error:

Traceback (most recent call last):
  File "ex.py", line 1, in <module>
    from math import pi
ImportError: cannot import name 'pi'

This just seems very weird to me, and through some research I've read a bit about circular dependencies but I don't think that's really relevant. Any help would be great!

vaultah
  • 40,483
  • 12
  • 109
  • 137
Jake
  • 265
  • 3
  • 10

1 Answers1

3

This works well on Python 3.4.3:

>>> from math import pi
>>> pi
3.141592653589793

Check whether you have another module named math by typing pip freeze in terminal, or check if you have a python file named math.py. If you do change its name.

tripleee
  • 158,107
  • 27
  • 234
  • 292
Doron Cohen
  • 976
  • 7
  • 13