Unable to import execute function from qiskit library

2.3k Views Asked by At

enter image description here

when I try to run this code, it gives me and error that it was unable to import execute from qiskit (error pasted below).

2 get_ipython().system('pip install --upgrade qiskit qiskit-aer')
      3 import qiskit
----> 4 from qiskit import QuantumCircuit, execute
      5 from qiskit_aer import Aer
      6 from qiskit.visualization import plot_histogram

ImportError: cannot import name 'execute' from 'qiskit' (/usr/local/lib/python3.10/dist-packages/qiskit/__init__.py)

I have tried upgrading qiskit which didn't work. I have also tried using transpile and the other functions but it changed my code too much and I didn't want that to happen.

3

There are 3 best solutions below

0
H.baghry On BEST ANSWER

The execute Function in qskit library is been removed from version 1.00 you can downgrade to version 0.46 and it will Run

2
davidryan On

One of the great things about qiskit is also one of the challenges, in that it updates quite quickly. The execute function has been deprecated since version o.46.0 (see notice here) and it was removed in the 1.0 release.

If you need to use an older version, such as following along a tutorial or quickstart, you can rollback to earlier releases and use the syntax for that release. For example: https://docs.quantum.ibm.com/api/qiskit/0.24/execute

from qiskit import QuantumCircuit, execute, BasicAer
 
backend = BasicAer.get_backend('qasm_simulator')
 
qc = QuantumCircuit(5, 5)
qc.h(0)
qc.cx(0, range(1, 5))
qc.measure_all()
 
job = execute(qc, backend, shots=4321)
0
Raghav On

You can use transpile in newer version. Refer: qiskit v1.0 migration guide