Search code examples
pythonqtpyside2

PySide2 Qt clashes with other Qt in the system?


I'm getting following error while running the following code.

Cannot mix incompatible Qt library (version 0x50c05) with this library (version 0x50d02)

How to debug this?

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

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

        self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"]

        self.button = QtWidgets.QPushButton("Click me!")
        self.text = QtWidgets.QLabel("Hello World")
        self.text.setAlignment(QtCore.Qt.AlignCenter)

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

        self.button.clicked.connect(self.magic)


    def magic(self):
        self.text.setText(random.choice(self.hello))


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

    widget = MyWidget()
    widget.resize(800, 600)
    widget.show()

    sys.exit(app.exec_())

Solution

  • The problem was that I was using qt 5.12.5 from conda-forge and pyqt from pip wheels (https://github.com/conda-forge/conda-forge.github.io/issues/921#issuecomment-553094850).

    Finally, I got rid of that annoying bug as follows:

    1. by making sure I have same versions of PyQt5 and PySide2 installed
    2. by removing qt from my environment: conda remove -n myEnv qt