简体   繁体   English

当我已经导入所有 qiskit 函数时,为什么在我的程序中出现“NameError: name 'qiskit' is not defined”

[英]Why am I getting "NameError: name 'qiskit' is not defined" on my program when I already imported all qiskit functions

I'm using the IBM quantum lab to run my python program.我正在使用 IBM 量子实验室来运行我的 python 程序。 I imported all these functions/libraries:我导入了所有这些函数/库:

from ibm_quantum_widgets import CircuitComposer从 ibm_quantum_widgets 导入 CircuitComposer

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit从 qiskit 导入 QuantumRegister、ClassicalRegister、QuantumCircuit

from numpy import pi从 numpy 导入 pi

import json进口 json

import ast导入 ast

from qiskit import *从 qiskit 导入 *

from qiskit import QuantumCircuit, execute, BasicAer从 qiskit 导入 QuantumCircuit,执行,BasicAer

from qiskit.tools.monitor import job_monitor从 qiskit.tools.monitor 导入 job_monitor

from qiskit import IBMQ从 qiskit 导入 IBMQ

from qiskit import BasicAer从 qiskit 导入 BasicAer

just to make sure I literally got everything from the qiskit library (if that's the right term, I'm kind of a beginner).只是为了确保我确实从 qiskit 库中获得了所有内容(如果这是正确的术语,我是一个初学者)。 It's overkill but I did it mainly because every time I run my program and get to this line of code:这是矫枉过正,但我这样做主要是因为每次我运行我的程序并进入这行代码时:

measure = qiskit.execute(circuit, backend=thequantumcomputer, shots=1)测量=qiskit.execute(电路,后端=量子计算机,镜头=1)

I get a nameerror, qiskit not defined.我收到一个名称错误,未定义 qiskit。 I wanted to import everything just to be sure that wasn't the issue.我想导入所有内容以确保这不是问题。 Does anyone understand what possibly could be the issue here?有谁知道这里可能是什么问题? for context, I'll copy and paste the code before the error:对于上下文,我将复制并粘贴错误之前的代码:

            IBMQ.load_account()
            provider = IBMQ.get_provider(hub = 'ibm-q')
            thequantumcomputer = provider.get_backend('ibmq_qasm_simulator')
            
            #measures all the circuits
            circuit.measure(0,0) 
            circuit.measure(1,1)
            circuit.measure(2,2)
            circuit.measure(3,3)
            circuit.measure(4,4)
            circuit.measure(5,5)
            circuit.measure(6,6)
            circuit.measure(7,7)
            circuit.measure(8,8)

            measure = qiskit.execute(circuit, backend=thequantumcomputer, shots=1)

Thanks for any suggestions you have:)感谢您的任何建议:)

You would need to say你需要说

import qiskit

What you have said is你说的是

from qiskit import execute

That brings in the name execute .这带来了名称execute It does not define a name called qiskit .它没有定义一个名为qiskit的名称。 So, you could say:所以,你可以说:

            measure = execute(circuit, backend=thequantumcomputer, shots=1)

Or you could just use import qiskit instead of importing all the individual names.或者您可以只使用import qiskit而不是导入所有个人名称。 I tend to prefer that, because then I know exactly where the name came from.我倾向于这样,因为那时我确切地知道这个名字的来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在函数中定义变量名时,为什么会出现 NameError? - Why am I getting a NameError when I've defined my variable name in a function? NameError:未定义全局名称,为什么会收到该错误? - NameError: global name is not defined, why am I getting that error? 为什么会收到(NameError:未定义全局名称“ secondRoom”)? - Why am I getting (NameError: global name 'secondRoom' is not defined)? 为什么会出现NameError:未定义名称'array' - Why am I getting NameError: name 'array' is not defined 为什么会出现以下错误:NameError:未定义名称'models' - Why am I getting the following error: NameError: name 'models' is not defined 为什么我得到NameError:没有定义全局名称'spacing' - why am i getting NameError: global name 'spacing' is not defined 为什么我收到此错误“NameError:name'self'未定义。” - Why am I getting this error “NameError:name 'self' is not defined.” 为什么我会得到这个? “NameError:名称'响应'未定义” - Why am I getting this? “NameError: name 'Response' is not defined” 为什么我会收到“NameError: name 'df2' is not defined”错误? - Why am i getting “ NameError: name 'df2' is not defined” error? 为什么我得到这个 NameError: name "dt' is not defined - Why am I getting this NameError: name "dt' is not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM