Sometimes you need to know which version of PySide2 you have installed. Below are two ways of getting this information from your system -- first using the pip
command and second, from PySide2 itself.
Finding the Version From the Command Line
If you just want to know which version is installed for yourself, and you installed the package using pip
, you can use the following command to return the current version:
$ pip show pyside2
Name: PySide2
Version: 5.15.8
Summary: Python bindings for the Qt cross-platform application and UI framework
Home-page: https://pyside.org
Author:
Author-email: Qt for Python Team <pyside@qt-project.org>
License: LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
Location: .../lib/python3.13/site-packages
Requires: PySide2-Addons, PySide2-Essentials, shiboken2
Required-by:
The second line on this output shows the PySide2 version number you're using in your current Python environment. In this particular example, we're using PySide2 version 5.15.8.
Finding the Version Within Your Code
Sometimes, you need to know the version within your code. Perhaps you're a library developer, and your code uses certain features of PySide2 that are only available in specific versions, and you want to disable these in earlier versions.
In that case, you can use the following code to get the version number.
>>> import PySide2
>>> import PySide2.QtCore
>>> print("Qt: v", PySide2.QtCore.__version__, "\tPyQt: v", PySide2.__version__)
Qt: v 5.15.8 PyQt: v 5.15.8
This also gives you the version of Qt. In my machine, I'm running version 5.15.8 of both Qt and PySide2.
Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PySide6 Edition) The hands-on guide to making apps with Python — Over 15,000 copies sold!