Skip to content

ImportError: cannot import name 'BaseEstimator' from 'qiskit.primitives' #909

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
umairinayat opened this issue Apr 12, 2025 · 2 comments
Closed

Comments

@umairinayat
Copy link

When I try to import the EstimatorQNN from the qiskit_machine_learning.neural_networks module, I encounter an ImportError related to BaseEstimator. The error message is as follows:
ImportError: cannot import name 'BaseEstimator' from 'qiskit.primitives' (/usr/local/lib/python3.11/dist-packages/qiskit/primitives/__init__.py)
Steps to Reproduce:

  1. Install the latest version of Qiskit and Qiskit Machine Learning.
  2. Run the following code:

from qiskit_machine_learning.neural_networks import EstimatorQNN
3. The error occurs when the import statement for EstimatorQNN is executed.
Expected Behavior:
The EstimatorQNN should import without errors, as documented in the Qiskit Machine Learning tutorials.

Actual Behavior:
An ImportError occurs because BaseEstimator cannot be found in the qiskit.primitives module.

Environment:
Python version: 3.11

Qiskit version: 0.38.0

Qiskit Machine Learning version: 0.3.0

Operating System: Linux

Additional Information:
I have tried upgrading both Qiskit and Qiskit Machine Learning using the following commands:
pip install --upgrade qiskit pip install --upgrade qiskit-machine-learning
However, the issue persists.

@woodsp-ibm
Copy link
Member

I am confused. You list steps to reproduce which say to install the latest versions of Qiskit And Qiskit ML yet your environment shows 0.38 for Qiskit and 0.3.0 for Qiskit ML which are ancient.

I would install the latest Qiskit ML: 0.8.2 and a version of Qiskit < 2.0.0 say 1.4.2 which is the latest version less than 2.0. It needs < 2.0 as ML is not yet compatible with Qiskit 2.0 (as per issue #897 here which is for adding support for this). Version 2.0 removed the Primitives Version 1, of which BaseEstimator is one of those classes, leaving the newer Version 2 ones which ML has yet to support.

@edoaltamura
Copy link
Collaborator

edoaltamura commented Apr 16, 2025

Indeed, I would suggest upgrading your Qiskit ML to version 0.8.2 - which we actively support - and Qiskit < 2.0.0. You may find the requirements.txt file helpful in checking which dependencies are supported by Qiskit ML versions.

Note that running pip install --upgrade qiskit may not be sufficient to upgrade qiskit from a 0.x version to 1.x; see the migration guide, particularly the following:

Do not try to upgrade an existing Python virtual environment to Qiskit 1.0 in-place.
We will not make similar breaking packaging changes in the future. This is a one-time event, at the release of Qiskit 1.0, specifically so that our packaging story will be as easy as possible in the future.

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

No branches or pull requests

3 participants