Can´t import qiskit, attribute error in numpy: " 'numpy.random' has no attribute 'default_rng'"
Solution 1
I got almost the same error as:
AttributeError: module 'numpy.random' has no attribute 'default_rng'
with the numpy version of '1.16.2'
numpy.__version__
'1.16.2'
As a solution, either you need to put these lines at the top of your file:
import numpy
numpy.random.bit_generator = numpy.random._bit_generator
Or the your current numpy version probably is <= 1.17
. Hence, you need to update the NumPy version. For instance, I have updated it on Anaconda environment as:
conda update numpy
And the current version is:
numpy.__version__
'1.19.2'
Updates take time because of lots of dependencies of NumPy. Hopefully, the issue is resolved on my side!
Solution 2
You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs
Solution 3
if you're using jupyter in anaconda - uninstalling, reinstalling and restarting the kernel worked for me similar here: AttributeError: module 'numpy' has no attribute '__version__'
- !pip uninstall -y numpy
- !pip install numpy
- RESTART KERNEL
Abner
Updated on June 08, 2022Comments
-
Abner about 2 years
I´m using Python 3 and I´m working in jupyter, when I try to import qiskit the following error is showed:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-2-578b7f7e9727> in <module> ----> 1 import qiskit ~\AppData\Roaming\Python\Python36\site-packages\qiskit\quantum_info\synthesis\two_qubit_decompose.py in __init__(self, unitary_matrix) 169 # D, P = la.eig(M2) # this can fail for certain kinds of degeneracy 170 for i in range(100): # FIXME: this randomized algorithm is horrendous --> 171 state = np.random.default_rng(i) 172 M2real = state.normal()*M2.real + state.normal()*M2.imag 173 _, P = la.eigh(M2real) AttributeError: module 'numpy.random' has no attribute 'default_rng'
-
Abner about 4 yearsI´ve update numpy, but it´s in version 1.11.3, something wrong I must done while updating numpy. I´m going to check it, thanks for your help.