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
  • 44,105
  • 12
  • 114
  • 143
Jake
  • 275
  • 4
  • 11

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
  • 175,061
  • 34
  • 275
  • 318
Doron Cohen
  • 1,026
  • 8
  • 13