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

12,477

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__'

  1. !pip uninstall -y numpy
  2. !pip install numpy
  3. RESTART KERNEL
Share:
12,477
Abner
Author by

Abner

Updated on June 08, 2022

Comments

  • Abner
    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
    Abner about 4 years
    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.