Skip to content

cannot import "BaseBackent" from "qiskit.providers" #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JohnyMarley opened this issue Dec 7, 2023 · 6 comments · Fixed by #580
Closed

cannot import "BaseBackent" from "qiskit.providers" #577

JohnyMarley opened this issue Dec 7, 2023 · 6 comments · Fixed by #580

Comments

@JohnyMarley
Copy link

Environment

  • Qiskit Optimization version: 0.6.0
  • Python version: 3.12.0
  • Operating system: linux

What is happening?

I am trying to run the quiskit optimization example from:
https://qiskit.org/ecosystem/optimization/tutorials/02_converters_for_quadratic_programs.html

And get the following import error:

ImportError: cannot import name 'BaseBackend' from 'qiskit.providers' (/home/jdara/anaconda3/envs/quant4/lib/python3.12/site-packages/qiskit/providers/init.py)

How can we reproduce the issue?

First run these pip commands:

pip install qiskit
pip install qiskit-ibm-runtime
pip install qiskit[visualization]
pip install qiskit-optimization
pip install 'qiskit-optimization[cplex]'
pip install 'qiskit-optimization[cvx]'
pip install 'qiskit-optimization[matplotlib]'

Then run in a jupyternotebook:

from qiskit_optimization.algorithms import CplexOptimizer
cplex_optimizer = CplexOptimizer()

This results in this error:

ImportError: cannot import name 'BaseBackend' from 'qiskit.providers' (/home/jdara/anaconda3/envs/quant4/lib/python3.12/site-packages/qiskit/providers/init.py)

I am running in a anaconda environment if this should be relevant

What should happen?

I would expect the import not to go wrong

Any suggestions?

No response

@woodsp-ibm
Copy link
Member

BaseBackend was deprecated and removed from Qiskit a long time ago (0.21.0). The above optimization code does not even reference that class. I would check whether you can import anything from qiskit like QuantumCircuit with getting the same error. If I do the same - though I did it in a Python command line not a notebook - it works fine. You should also check what environment your notebook is using.

I will also note that only the very latest version of Qiskit supports Python 3.12. None of the rest of the above do. I would check what your installation as to what is actually there. For now 3.11 is the newest version consistent with all those packages.

@Sofranac-Boro
Copy link

I can confirm that I can reproduce the error after following the same steps for python3.12. What happened in my environment is that pip install 'qiskit-optimization[cplex]' downgrades the qiskit-optimization back to 0.3.2

Installing collected packages: qiskit-optimization
  Attempting uninstall: qiskit-optimization
    Found existing installation: qiskit-optimization 0.6.0
    Uninstalling qiskit-optimization-0.6.0:
      Successfully uninstalled qiskit-optimization-0.6.0
Successfully installed qiskit-optimization-0.3.2

@woodsp-ibm
Copy link
Member

There is no cplex for 3.12 (again latest version supported is 3.11). In optimization 0.3.2 it has to install cplex if Python < 3.10, so I guess it was able to figure it could satisfy that request for the optional install by dropping back to 0.3.2 whereupon it does nothing in essence as far as cplex is concerned.

@JohnyMarley
Copy link
Author

Thanks for the reply and help! 👍

@SarevalasaBharathkumar
Copy link

i am facing an error with the import line
from qiskit_machine_learning.algorithms import VQR
output:
ImportError: cannot import name 'BackendV1' from 'qiskit.providers' (/home/rguktrkvalley/anaconda3/envs/quantum_env/lib/python3.10/site-packages/qiskit/providers/init.py)

Description: I tried to uninstall and install packages. And also setting up in a separate environment but still i am facing the issue cannot import name backendve from qiskit.providers

could you please help to resolve this issue.

@woodsp-ibm
Copy link
Member

It seems like you have installed the latest Qiskit 2.0 which removed a lot of earlier deprecated classes such as the one you mention and also V1 primitives which ML depends on still. ML is not compatible with Qiskit 2.0 at present. I would suggest installed the latest Qiskit version before 2.0 ie. 1.4.2 Do pip install qiskit==1.4.2 and things should then work for you, Same with Optimization its not compatible wih Qiskit 2.0 - maybe you have both installed and you are trying to run Optimization stuff - just confused by the fact that your post only alludes to ML and says nothing about Qiskit Optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants