Error importing Qiskit Aer when running Qiskit

77 Views Asked by At

I am getting an error when I try to import Aer in Qiskit. I am running this command:

from qiskit import Aer

And I am getting this error:

cannot import name 'aer' from 'qiskit' (/opt/conda/lib/python3.10/site-packages/qiskit/__init__.py)

Use %tb to get the full traceback.

I have tried to solve this by reinstalling with pip install qiskit-aer, as well as restarting the kernel, uninstalling and reinstalling Qiskit, etc. Note that I'm working in IBM Quantum Lab.

1

There are 1 best solutions below

0
Nina On

The problem indeed looks like Aer isn't importing, which is usually a sign that it hasn't been installed or might be a previous breaking version. Also note that the version of Aer you are calling isn't supported anymore. See the documentation here: https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0-features#aer

The qiskit.Aer object is not available in Qiskit 1.0. Instead, use the same object from the qiskit_aer namespace, which is a drop-in replacement.

So first let's try to install or upgrade Aer to make sure you're on the correct version.

pip install --upgrade qiskit
pip install --upgrade qiskit-aer

This is probably the fix. But another issue can be that it's not running on the same Python environment as Qiskit. You can check which Python environment you are using by running the following command.

import sys
print(sys.executable)