【问题标题】:Can´t import qiskit, attribute error in numpy: " 'numpy.random' has no attribute 'default_rng'"无法导入 qiskit,numpy 中的属性错误:“‘numpy.random’没有属性‘default_rng’”
【发布时间】:2020-09-16 12:08:17
【问题描述】:

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

【问题讨论】:

  • 什么 numpy 版本?
  • 你能显示你的代码吗?它看起来不像 qiskit 错误,而是 numpy 错误

标签: python numpy import attributes qiskit


【解决方案1】:

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

  1. !pip 卸载 -y numpy
  2. !pip install numpy
  3. 重启内核

【讨论】:

    【解决方案2】:

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

    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 版本可能是&lt;= 1.17。因此,您需要更新 NumPy 版本。例如,我在 Anaconda 环境中将其更新为:

    conda update numpy
    

    而当前版本是:

    numpy.__version__
    '1.19.2'
    

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 我已经更新了 numpy,但它在 1.11.3 版本中,我在更新 numpy 时必须做一些错误的事情。我去看看,谢谢你的帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2019-07-09
      • 2021-03-10
      • 1970-01-01
      • 2019-09-10
      • 2020-12-11
      • 1970-01-01
      相关资源
      最近更新 更多