Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an ImportError: cannot import name 'Random' from 'random' [duplicate]

I ran my code many times in my computer and didn't get this error. But all of a sudden this came

  File "e:\Python 3.8.0\lib\site-packages\comtypes\client\_code_cache.py", lin
    import ctypes, logging, os, sys, tempfile, types
  File "e:\Python 3.8.0\lib\tempfile.py", line 45, in <module>
    from random import Random as _Random
ImportError: cannot import name 'Random' from 'random' (e:\python codes\random
like image 690
Ebinesh. A Avatar asked Nov 02 '25 00:11

Ebinesh. A


1 Answers

You've probably created a file called random.py. Since that is the exact name of a built-in module, your program will get mixed up, and import the file you've created.

To fix this, rename your fie to something like random2.py, and it should work.

like image 127
Ann Zen Avatar answered Nov 04 '25 13:11

Ann Zen