Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can´t import qiskit, attribute error in numpy: " 'numpy.random' has no attribute 'default_rng'"

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'
like image 861
Abner Avatar asked Dec 08 '22 10:12

Abner


1 Answers

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!

like image 167
ozturkib Avatar answered Feb 17 '23 00:02

ozturkib