Getting Started

To get started with Qt for Python, install the following prerequisites:

  • Python v3.5 or later
  • libclang v3.9 or later
  • Optional: a virtual environment, such as venv or virtualenv

With these installed, you are ready to install the Qt for Python packages using the pip wheel. Run the following command from your command prompt to install:

python -m pip install --index-url= pyside2 --trusted-host

Now that you have Qt for Python installed, you can test your setup by running the following Python constructs to print version information:

import PySide2.QtCore

# Prints PySide version
# e.g. 1.0.2

# Gets a tuple with each version component
# e.g. (1, 0, 2, 'final', 1)

# Prints the Qt version used to compile PySide
# e.g. "5.11.0"

# Gets a tuple with each version components of Qt used to compile PySide
# e.g. (5, 11, 0)

Note that the Qt version used to compile Qt for Python may differ from the version used to run Qt for Python. To print the current running Qt version number, you can use:


Your Qt for Python setup is ready, so try exploring it further by developing a simple application that prints “Hello World” in several languages. The following instructions will guide you through the development process:

  • Create a new file named, and add the following imports to it.

    import sys
    import random
    from PySide2 import QtCore, QtWidgets, QtGui

    The PySide2 Python module provides access to the Qt APIs as its submodule. In this case, you are importing the QtCore, QtWidgets, and QtGui submodules.

  • Define a class named MyWidget, which extends QWidget and includes a QPushButton and QLabel.

    class MyWidget(QtWidgets.QWidget):
        def __init__(self):
            self.hello = ["Hallo Welt", "你好,世界", "Hei maailma",\
                "Hola Mundo", "Привет мир"]
            self.button = QtWidgets.QPushButton("Click me!")
            self.text = QtWidgets.QLabel("Hello World")
            self.text.setFont(QtGui.QFont("Titillium", 30))
            self.button.setFont(QtGui.QFont("Titillium", 20))
            self.layout = QtWidgets.QVBoxLayout()
        def magic(self):

    The MyWidget class has the magic member function that randomly chooses an item from the list hello. This function is called when you click the button.

  • Now, add a main function where you instantiate MyWidget and show it.

    if __name__ == "__main__":
        app = QtWidgets.QApplication([])
        widget = MyWidget()
        widget.resize(800, 600)

Your example is ready to be run. Try clicking the button at the bottom and see which greeting you get.