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

3

6

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'
Thinkable answered 29/5, 2020 at 1:27 Comment(2)
what numpy version?Ynes
can you show your code? It doesn't look like a qiskit error but a numpy errorLaurence
T
8

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!

Thorfinn answered 30/10, 2020 at 9:2 Comment(0)
A
7

You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs

Akvavit answered 29/5, 2020 at 8:52 Comment(1)
I´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.Thinkable
V
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__'

  1. !pip uninstall -y numpy
  2. !pip install numpy
  3. RESTART KERNEL
Vinnievinnitsa answered 9/5, 2021 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.