4

我正在使用 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'
4

3 回答 3

8

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

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

使用 numpy 版本的'1.16.2'

numpy.__version__
'1.16.2'

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

import numpy
numpy.random.bit_generator = numpy.random._bit_generator

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

conda update numpy

当前版本是:

numpy.__version__
'1.19.2'

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

于 2020-10-30T09:02:00.600 回答
6

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

于 2020-05-29T08:52:59.313 回答
1

如果您在 anaconda 中使用 jupyter - 卸载、重新安装和重新启动内核对我来说类似:AttributeError: module 'numpy' has no attribute '__version__'

  1. !pip 卸载 -y numpy
  2. !pip 安装 numpy
  3. 重启内核
于 2021-05-09T11:02:21.967 回答