ImportError: cannot import name randbits

Hi All,
We have installed python 3.8 using the “wget” method by referring to the official python website.
When running a python script, we are getting the error as below

ImportError: cannot import name randbits

Before that error, there are several lines which were printed related to numpy packages like pickle, random etc…
We browsed the Internet regarding this error but no relevant results appeared.Used below statements to uninstall and reinstall numpy but the error persists.

sudo /usr/bin/python3.8 -m pip uninstall numpy
sudo /usr/bin/python3.8 -m pip install numpy

Please suggest way forward

Please post the entire traceback, starting with the line “Traceback”, not just the final error message.

Please copy and paste it, don’t use a screen shot or photo.

I am afraid i cannot paste the entire error message as it is related to business… i shall try to post the relevant screenshot

Here it is

Traceback (most recent call last):
File <> line 81 , in

File <> line 81 , in

File “/usr/lib/python3.8/importlib/” , line 127 ,in import_module
return _bootstrap._gcd_import(name[level:],package,level)

File “” line , in _gcd_import
File “” line ,in _find_and_load
File “” line , in _find_and_load_unlocked
File “” line , in _load_unlocked
File “” line , in _call_with_frames_removed
File “/home/jupyter/<” , line , in

import numpy as np
File “root/.local/share/virtualenvs/jupyter/lib/python3.8/site-packages/numpy/” line 151 in
from .import random
File “root/.local/share/virtualenvs/jupyter/lib/python3.8/site-packages/numpy/random/” line 180 in
From import .pickle
File “root/.local/share/virtualenvs/jupyter/lib/python3.8/site-packages/numpy/random/” line 180 in
from .mtrand import RandomState
File “mtrand.pyx” , line 1 in init numpy.random.mtrand
File “bit_generator.pyx” , line 38 in init numpy.random.bit_generator
Import Error: Cannot import name randbits

Are you sure this is the complete, unedited traceback?

Maybe its normal for Jupyter, but it seems to be all wrong, with parts missing, impossible file names and invalid lines of code.

In any case, I can see no documentation that suggests that numpy.random.bit_generator has ever existed.

Maybe a numpy/jupyter expert can chime in with better information.

It looks as though it’s failing to find secrets.randbits. If you add import secrets; print(secrets) at the top of your failing script (before the NumPy imports), what output do you see?

1 Like

i pasted with full message…looks like some lines got cropped. thank you for the reply

ok…will try that and let you know… thank you

Thanks Mark…
Yes, we had a folder in our code repo by the name “secrets” which is clashing with the “secrets” module of python and there by not recognizing the “secrets.randbits”
We changed the secrets folder to “gcp-secrets” and now the error is gone.