qiskit-metapackage icon indicating copy to clipboard operation
qiskit-metapackage copied to clipboard

qiskit.__version__ shows wrong version number

Open mikbuch opened this issue 1 year ago • 2 comments

Informations

  • Qiskit version: 0.37.1
  • Python version: 3.10.4
  • Operating system: macOS

What is the current behavior?

qiskit.__version__ shows version 0.21.1 instead of 0.37.1

Steps to reproduce the problem

pip install qiskit==0.37.1
python3 -c "import qiskit; print(qiskit.__version__)"

Out:

0.21.1

Validation:

pip show qiskit

Out:

Name: qiskit
Version: 0.37.1
Summary: Software for developing quantum computing programs
Home-page: https://github.com/Qiskit/qiskit
Author: Qiskit Development Team
Author-email: [email protected]
License: Apache 2.0
Location: /Users/mbuch/.local/share/virtualenvs/qfmri-R8bnGQeP/lib/python3.10/site-packages
Requires: qiskit-aer, qiskit-ibmq-provider, qiskit-terra
Required-by:

What is the expected behavior?

The command:

python3 -c "import qiskit; print(qiskit.__version__)"

Should return:

0.37.1

Suggested solutions

I thought this is taken from the version reported in PyPi. For the first time I see such behaviour, so I don't yet have idea how to fix that.

Maybe it reports qiskit-terra's version: https://github.com/Qiskit/qiskit/blob/master/setup.py#L29

In setup.py the main version is ok: https://github.com/Qiskit/qiskit/blob/master/setup.py#L71

mikbuch avatar Aug 11 '22 13:08 mikbuch

Yeah, this is intended behavior, it's a quirk/artifact of how Qiskit was/is built. The qiskit package on PyPI that you install with pip is represented by this git repository. It's a "metapackage" or package of packages that doesn't contain any source code and is setup to install all the packages that make up the qiskit python namespace (the contents of import qiskit). Historically that was the qiskit elements (terra, aer, ignis, and aqua) that all lived under qiskit.*. As part of that the root of the qiskit namespace was qiskit-terra, so the __version__ attribute for the qiskit namespace in python is qiskit-terra's version number.

If you'd like to see the full set of installed qiskit packages we export a separate entrypoint qiskit.__qiskit_version__ which returns a dictionary of all the installed qiskit packages including the metapackage version you're looking for.

mtreinish avatar Aug 11 '22 13:08 mtreinish

@mtreinish , thank you for this immediate response!

I confirm, with the command:

python3 -c "import qiskit; print(qiskit.__qiskit_version__)"

I got:

{'qiskit-terra': '0.21.1', 'qiskit-aer': '0.10.4', 'qiskit-ignis': None, 'qiskit-ibmq-provider': '0.19.2', 'qiskit': '0.37.1', 'qiskit-nature': None, 'qiskit-finance': None, 'qiskit-optimization': None, 'qiskit-machine-learning': None}

that includes the metapackage version number: 'qiskit': '0.37.1'.

I think I understand the historic/legacy reasons behind the fact that terra's version number is displayed with qiskit namespace (qiskit.__version__). However, do you think it is possible to change that, so the __version__ attribute would show the version of the metapackage (the one that is published at PyPI)? Or maybe it is possible to "redirect" this attribute to show the output of qiskit.__qiskit_version__ instead? I am not an expert in Python module's (meta)attributes.

I just want to say that leaving things as they are now can be very confusing for the new users (such as myself), as the majority of the popular modules indicated the main (meta) package's version (numpy, scipy, etc.) -- i.e., the one that is also available at PyPI and via pip show <package>.

Thank you for the help again, and I hope the development of qiskit is going fine, it is a great package!

mikbuch avatar Aug 11 '22 14:08 mikbuch