Jake Jake - 1 year ago 108
Python Question

Error: cannot import name 'pi'

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!

Answer Source

This works well on Python 3.4.3:

>>> from math import pi
>>> pi

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download