Installing

Qt for Python is available through PyPA using pip under the name pyside6. In the example below we setup a venv environment in which we will install the latest version of Qt for Python:

  1. mkdir qt-for-python
  2. cd qt-for-python
  3. python3 -m venv .
  4. source bin/activate
  5. (qt-for-python) $ python --version
  6. Python 3.9.6

When the environment is setup, we continue to install pyside6 using pip:

  1. (qt-for-python) $ pip install pyside6
  2. Collecting pyside6
  3. Downloading [ ... ] (60.7 MB)
  4. Collecting shiboken6==6.1.2
  5. Downloading [ ... ] (1.0 MB)
  6. Installing collected packages: shiboken6, pyside6
  7. Successfully installed pyside6-6.1.2 shiboken6-6.1.2

After the installation, we can test it by running a Hello World example from the interactive Python prompt:

  1. (qt-for-python) $ python
  2. Python 3.9.6 (default, Jun 28 2021, 06:20:32)
  3. [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> from PySide6 import QtWidgets
  6. >>> import sys
  7. >>> app = QtWidgets.QApplication(sys.argv)
  8. >>> widget = QtWidgets.QLabel("Hello World!")
  9. >>> widget.show()
  10. >>> app.exec()
  11. 0
  12. >>>

The example results in a window such as the one shown below. To end the program, close the window.

Installing - 图1