Sometimes you need to know which version of PyQt or PySide you have installed.
Below are two methods of getting this information from your system -- first using pip
and second from PyQt/PySide itself.
Finding the version from the command prompt
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.
- PyQt5
- PyQt6
- PySide2
- PySide6
pip show pyqt5
pip show pyqt6
pip show pyside2
pip show pyside6
This outputs the metadata from the pip
database, including the version number, e.g.
Name: PyQt5
Version: 5.15.1
Summary: Python bindings for the Qt cross platform application toolkit
Home-page: https://www.riverbankcomputing.com/software/pyqt/
Author: Riverbank Computing Limited
Author-email: info@riverbankcomputing.com
License: GPL v3
Location: /home/martin/.local/lib/python3.7/site-packages
Requires: PyQt5-sip
Required-by:
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 PyQt which are only available in specific versions and you want to disable this in earlier versions.
In that case you can use the following code to get the version number. This also gives you the version of Qt.
- PyQt5
- PyQt6
- PySide2
- PySide6
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
print("Qt: v", QT_VERSION_STR, "\tPyQt: v", PYQT_VERSION_STR)
from PyQt6.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
print("Qt: v", QT_VERSION_STR, "\tPyQt: v", PYQT_VERSION_STR)
import PySide2
import PySide2.QtCore
print("Qt: v", PySide2.QtCore.__version__, "\tPyQt: v", PySide2.__version__)
import PySide6
import PySide6.QtCore
print("Qt: v", PySide6.QtCore.__version__, "\tPyQt: v", PySide6.__version__)
You can run this by opening up a Python shell and copy-pasting in the above code. On my machine it produces the following output.
- PyQt5
- PyQt5
- PySide2
- PySide6
>>> from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
>>> print("Qt: v", QT_VERSION_STR, "\tPyQt: v", PYQT_VERSION_STR)
Qt: v 5.15.2 PyQt: v 5.15.6
>> from PyQt6.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
>>> print("Qt: v", QT_VERSION_STR, "\tPyQt: v", PYQT_VERSION_STR)
Qt: v 6.2.0 PyQt: v 6.2.0
>>> import PySide2
>>> import PySide2.QtCore
>>> print("Qt: v", PySide2.QtCore.__version__, "\tPyQt: v", PySide2.__version__)
Qt: v 5.15.2 PyQt: v 5.15.2
>>> import PySide6
>>> import PySide6.QtCore
>>> print("Qt: v", PySide6.QtCore.__version__, "\tPyQt: v", PySide6.__version__)
Qt: v 6.2.0 PyQt: v 6.2.0