0

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_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Wasim Aftab
  • 638
  • 1
  • 8
  • 16
  • The problem has nothing to do with your code but it seems that you have Qt installed whose version is different from the one you installed with PySide2. – eyllanesc Nov 12 '19 at 18:11
  • 1
    the problem has nothing to do with pyqt – eyllanesc Nov 12 '19 at 18:12
  • I also thought so but I'm not able to decide what should be the best way to debug this. should I downgrade Qt from PySide2 or I should upgrade pyQt? – Wasim Aftab Nov 12 '19 at 18:14
  • Recommendation: uninstall both. And create a virtualenv for each library so you avoid problems. – eyllanesc Nov 12 '19 at 18:18
  • On the other hand, both bindings currently use the same version of Qt, Qt 5.13.2, which should not cause you problems. – eyllanesc Nov 12 '19 at 18:19
  • I did create a venv, interstingly i find following, **print (PySide2.QtCore.__version__) = 5.13.2** but from PyQt5 import QtCore **print(QtCore.PYQT_VERSION)=330755** and on the other hand qdiag output shows **Qt 5.12.5 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 7.3.0) on "xcb"** – Wasim Aftab Nov 12 '19 at 18:22
  • I have recommended you create 2 virtualenvs: one for PyQt5 and one for PySide2 – eyllanesc Nov 12 '19 at 18:30
  • why PySide2.QtCore and QtCore for pyQt5 do not show same version in the freshly installed environment – Wasim Aftab Nov 12 '19 at 18:30
  • On the other hand update PyQt5 since the latest version is PyQt5 5.13.2 that uses Qt 5.13.2 – eyllanesc Nov 12 '19 at 18:31
  • Because you haven't installed the latest version of both. – eyllanesc Nov 12 '19 at 18:31
  • **pip freeze | grep -i "^PyQt" PyQt5==5.13.2 PyQt5-sip==12.7.0 PyQtWebEngine==5.12.1** (pyQt) wasim@DNA:/opt/Anaconda3/envs$ **pip freeze | grep -i "^PySide" PySide2==5.13.2** still getting that error and still qdiag output shows **Qt 5.12.5 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 7.3.0) on "xcb"** – Wasim Aftab Nov 12 '19 at 18:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/202219/discussion-between-wasim-aftab-and-eyllanesc). – Wasim Aftab Nov 12 '19 at 18:45
  • So it's probably a conda bug, report it. – eyllanesc Nov 12 '19 at 18:47
  • I filed a conda bug https://github.com/conda/conda/issues/9432, but still wondering if qtdiag output has some clue towards fixing this bug – Wasim Aftab Nov 12 '19 at 19:54

1 Answers1

0

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
Wasim Aftab
  • 638
  • 1
  • 8
  • 16