ImportError: Cannot imporrt name SystemRandom

See original GitHub issue

Reproducing code example:

import numpy as np
import matplotlib.pyplot as plt
import time
import numpy as np
ysample = np.random.randint(-50, 50, 100)
xdata = []
ydata = []
plt.show()
axes = plt.gca()
axes.set_xlim(0, 100)
axes.set_ylim(-50, +50)
line, = axes.plot(xdata, ydata, 'r-')
for i in range(100):
    xdata.append(i)
    ydata.append(ysample[i])
    line.set_xdata(xdata)
    line.set_ydata(ydata)
    plt.draw()
    plt.pause(1e-17)
    time.sleep(0.1)
plt.show()

from . import random File “C:\Miniconda\envs\cv_course\lib\site-packages\numpy\random_init_.py”, line 181, in <module> from . import _pickle File “C:\Miniconda\envs\cv_course\lib\site-packages\numpy\random_pickle.py”, line 1, in <module> from .mtrand import RandomState File “mtrand.pyx”, line 9, in init numpy.random.mtrand File “mt19937.pyx”, line 1, in init numpy.random.mt19937 File “bit_generator.pyx”, line 43, in init numpy.random.bit_generator

Numpy/Python version information:

1.17.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

50reactions
rkerncommented, Nov 8, 2019

Do you have a module named random.py somewhere that isn’t the standard library’s random module? For example, is this script that you posted for us named random.py?

2reactions
WarrenWeckessercommented, Jun 26, 2022

Thanks @neilmolky. secrets is a module in the Python standard library, and it is used by NumPy in the bit_generator code of the random module: https://github.com/numpy/numpy/blob/6932eff2c2f634e9b88e940b9f5c02a24b6e71f6/numpy/random/bit_generator.pyx#L38

So if you have a Python file called secrets.py that shadows the standard library, it will break NumPy’s random module.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is this error code telling me? i.e. what do I need to fix
you have a file named random.py that override the module with the same name from the standard library (i.e. it try to import...
Read more >
I am getting error while importing numpy library in puthon
I just tried this and it works fine. However there is a comment at random — Generate pseudo-random numbers — Python 3.9.6 documentation[^],...
Read more >
ImportError: cannot import name randbits - Python Help
Hi All, We have installed python 3.8 using the “wget” method by referring to the official python website. When running a python script, ......
Read more >
ImportError: cannot import name Random : r/learnpython
ImportError : cannot import name Random. So I'm trying to run a script on a Zenoss server. I have Zenoss installed on Ubuntu...
Read more >
How to Fix : “ImportError: Cannot import name X” in Python?
You can solve the “ ImportError : Cannot import name X” Error by resolving the circular dependencies. You can do that either by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found