0
File "ex43.py", line 2, in <module>
    from random import randint
ImportError: cannot import name randint

Any suggestions for the randint error? I tried reinstalling python, with no luck.

2
  • 1
    import random; print(random.__file__) - what does it print? Commented Aug 16, 2015 at 19:23
  • can you please show the complete stacktrace? Commented Aug 16, 2015 at 19:23

1 Answer 1

5

Check any random.py or random.pyc file(which will override python random) in the current folder where ex43.py resides.If there, delete or rename that files.Also check import by

>>>import random
>>>print(random.__file__)

Check it is importing from packages

Sign up to request clarification or add additional context in comments.

4 Comments

I am still very new and not understanding all this, I do have a random.py and random.pyc in the folder. Not sure what I would do to check these. There is no randint file in their though.
When I run that, after deleting the random.py and random.pyc, I end up with this.
Traceback (most recent call last): File "testing1.py", line 1, in <module> import random File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.py", line 45, in <module> from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil ImportError: cannot import name log
:).so delete or rename math.py and math.pyc as you did for random.py in current directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.