无法导入 qiskit,numpy 中的属性错误:“'numpy.random' 没有属性 'default_rng'”

Abn*_*ner 4 python import attributes numpy qiskit

我正在使用 Python 3 并且在 jupyter 中工作,当我尝试导入 qiskit 时,显示以下错误:

---------------------------------------------------------------------------
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'
Run Code Online (Sandbox Code Playgroud)

ozt*_*kib 7

我得到了几乎相同的错误:

AttributeError: 模块 'numpy.random' 没有属性 'default_rng'

使用 numpy 版本 '1.16.2'

numpy.__version__
'1.16.2'
Run Code Online (Sandbox Code Playgroud)

作为解决方案,您需要将这些行放在文件的顶部:

import numpy
numpy.random.bit_generator = numpy.random._bit_generator
Run Code Online (Sandbox Code Playgroud)

或者您当前的 numpy 版本可能是<= 1.17. 因此,您需要更新 NumPy 版本。例如,我已在 Anaconda 环境中将其更新为:

conda update numpy
Run Code Online (Sandbox Code Playgroud)

当前版本是:

numpy.__version__
'1.19.2'
Run Code Online (Sandbox Code Playgroud)

由于 NumPy 的大量依赖关系,更新需要时间。希望问题在我这边得到解决!


Pau*_*ion 6

您需要 NumPy 1.17 或更高版本才能拥有 Qiskit 所需的新 RNG 函数