[英]Can´t import qiskit, attribute error in numpy: “ 'numpy.random' has no attribute 'default_rng'”
I´m using Python 3 and I´m working in jupyter, when I try to import qiskit the following error is showed:我正在使用 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'
I got almost the same error as:我得到了几乎相同的错误:
AttributeError: module 'numpy.random' has no attribute 'default_rng' AttributeError:模块“numpy.random”没有属性“default_rng”
with the numpy version of '1.16.2'
使用'1.16.2'
的 numpy 版本
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
.或者您当前的 numpy 版本可能是<= 1.17
。 Hence, you need to update the NumPy version.因此,您需要更新 NumPy 版本。 For instance, I have updated it on Anaconda environment as:例如,我在 Anaconda 环境中将其更新为:
conda update numpy
And the current version is:当前版本是:
numpy.__version__
'1.19.2'
Updates take time because of lots of dependencies of NumPy.由于 NumPy 的大量依赖关系,更新需要时间。 Hopefully, the issue is resolved on my side!希望问题在我这边得到解决!
You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs您需要 NumPy 1.17 或更高版本才能拥有 Qiskit 所需的新 RNG 功能
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__'如果您在 anaconda 中使用 jupyter - 卸载、重新安装和重新启动 kernel对我来说类似: AttributeError: module 'numpy' has no attribute '__version__'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.