osx - Cant import random python -


i having trouble importing random , randint in python

here error when "from random import randint"

traceback (most recent call last):   file "/users/noah/desktop/math.py", line 2, in <module>     random import randint   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/random.py", line 45, in <module>     math import log _log, exp _exp, pi _pi, e _e, ceil _ceil   file "/users/noah/desktop/math.py", line 2, in <module>     random import randint importerror: cannot import name randint 

and here error when "import random"

traceback (most recent call last):   file "/users/noah/desktop/math.py", line 2, in <module>     import random   file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/random.py", line 45, in <module>     math import log _log, exp _exp, pi _pi, e _e, ceil _ceil typeerror: 'module' object not callable 

when go /system/library/frameworks/python.framework/versions/2.7/lib/python2.7 check files has random.py random.pyc , random.pyo

python using path

>>> print random.__file__ /system/library/frameworks/python.framework/versions/2.7/lib/python2.7/random.pyc 

edit: have no clue happening

the traceback relatively clear:

  • you attempt import randint random;
  • inside python random module attempts import names math;
  • unfortunately, chose name 1 of own modules in working directory math , finds first;
  • when importing your math, attempts import random ... have circular import ... , fails.

conclusion:

in python 2, don't name modules identically core python modules ...


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -