PySide6 is a powerful Python GUI framework based on Qt, suitable for building cross-platform desktop applications.

If you want to use PySide6 in your project, it is very important to know how to install it through pip. This tutorial will guide you through the installation process of PySide6 step by step.

Install PySide6

Step 1: Check Python version

First, make sure you have Python 3.6 or above installed; you can check your Python version through the command python --version;

python --version
Python 3.11.5

Step 2: Update pip (optional)

To avoid compatibility issues during installation, it is recommended that you update pip to the latest version;

python.exe -m pip install --upgrade pip

Step 3: Install PySide6

Now, you can use pip to install PySide6:

pip install pyside6

You can also specify the version of PySide6:

pip install pyside6==6.5.2

Step 4: Verify the installation

After the installation is complete, you can verify whether PySide6 is installed successfully through the following simple test code;

from PySide6 import QtCore, QtWidgets, QtGui
import sys

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.button = QtWidgets.QPushButton("点这里")

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addWidget(self.button)

        self.button.clicked.connect(self.showMessage)

    @QtCore.Slot()
    def showMessage(self):
        msgBox = QtWidgets.QMessageBox()
        msgBox.setText("Hello world")
        msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
        ret = msgBox.exec()

if __name__ == "__main__":
    app = QtWidgets.QApplication([])

    widget = MyWidget()
    widget.resize(300, 200)
    widget.show()

    sys.exit(app.exec())
pyside6 running effect
Program running effect