Important: Please read the Qt Code of Conduct -

libQt5Core5 missmatch (beginner)

  • Hello,

    I am new to Qt and partially to Python too (I only did some simple plugins).

    I fight different issues with compatibility and have difficulties to even run basic PyQt sample programs and tutorials. So it's been about 3 days I'm stuck with the following code:

    import sys
    from PySide2.QtWidgets import QApplication
    from PyQt5 import uic
    if __name__ == "__main__":
        app = QApplication([])

    I guess it's obvious it tries to load a simple UI file and show the window.

    When I finally made QtCreator to choose the exact Python I want (/usr/bin/python3), it says it's missing a correct QtCore:

        from PyQt5 import QtCore, QtGui, QtWidgets
    ImportError: /usr/lib64/ version `Qt_5.14' not found (required by /home/<user>/.local/lib/python3.6/site-packages/PyQt5/
    21:31:31: /usr/bin/python3 exited with code 1

    But I have libQt5Core5 of version 5.9.7 installed:

    # rpm -qi libQt5Core5
    Name        : libQt5Core5
    Version     : 5.9.7
    Release     : lp151.4.3.1
    Architecture: x86_64
    Install Date: Čt 6. únor 2020, 21:42:07 CET
    Group       : Development/Libraries/X11
    Size        : 5844829
    License     : GPL-3.0 or SUSE-LGPL-2.1-with-digia-exception-1.1
    Signature   : RSA/SHA256, Čt 6. únor 2020, 14:43:56 CET, Key ID 598d0e63b3fd7e48
    Source RPM  : libqt5-qtbase-5.9.7-lp151.4.3.1.src.rpm
    Build Date  : Čt 6. únor 2020, 14:27:46 CET
    Build Host  : lamb12
    Relocations : (not relocatable)
    Packager    :
    Vendor      : openSUSE
    URL         :
    Summary     : Qt 5 Core Library

    I would asume, that it would suffice the requirements for 5.14. Any ideas? Maybe also any general tips to keep stuff consistent? seems that in 5 tutorials there are 5 different strategies how to install libraries (system packages, pip, virtual environments, ...).

    Qt Creator 4.11.1
    Qt 5.14.1 (GCC 5.3.1 20160406 (Red Hat 5.3.1-6), 64 bit)
    OpenSUSE Leap 15.1 Linux



  • Banned

    Okay first -- do your self a favor and do not use the Designer its not really meant to create quality GUIs and its just as easy to learn to do it right.

    Next I do not think you can mix PySide2 with PyQt5 but I could be wrong on it -- still I would never do that as everything you need should be contained in one or the other.

    Lastly here is a simple example of creating a PyQt5 window properly:

    from PyQt5.QtCore    import pyqtSlot
    from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QPushButton
    class MainWindow(QWidget):
        def __init__(self):
            Left = 500; Top = 200; Width = 225; Hight = 100
            self.setGeometry(Left, Top, Width, Hight)
            # -----
            self.btnPush = QPushButton('Push')
            # -----
            HBox = QHBoxLayout()
            # -----
            VBox = QVBoxLayout()
            # -----
        def Pushed(self):
            print('I was pushed')
    if __name__ == '__main__':
        MainEventThread = QApplication([])
        MainApp = MainWindow()

    If you need more extensive help learning python-qt I conduct a free online sort-of classroom (more like a lab situation) just PM me if you are interested

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are mixing two different bindings which are built with two different versions of Qt. That's the issue, either use PyQt5 or PySide2 but not both at the same time.

  • @SGaist and @Denni-0,

    Thank you for your suggestions, I realized I was mistaking them two bindings just for a Qt binging and a Qt library. Comes from mixed tutorials, when I tried to fix another error. And I'm back to square one here, because the original error is back, it tells me "uic" is not part of PySide2:

    Traceback (most recent call last):
      File "/home/<user>/Coding/Projects/Test1/", line 3, in <module>
        from PySide2.QtWidgets import QApplication, uic
    ImportError: cannot import name 'uic'
    02:01:49: /usr/bin/python3 exited with code 1

    My PySide2 seems to be up-to-date (regardless of fact, that I'm unsure if I should run it as superuser):

    > pip install --upgrade PySide2
    Defaulting to user installation because normal site-packages is not writeable
    Requirement already up-to-date: PySide2 in /usr/lib64/python3.6/site-packages (5.15.0a1.dev1584103015)
    Requirement already satisfied, skipping upgrade: shiboken2==5.15.0a1.dev1584103015 in /usr/lib64/python3.6/site-packages (from PySide2) (5.15.0a1.dev1584103015)


  • @Denni-0 said in libQt5Core5 missmatch (beginner):

    Okay first -- do your self a favor and do not use the Designer its not really meant to create quality GUIs and its just as easy to learn to do it right.

    As for this off topic comment, I decided to react in a separate answer. There are several reasons I'm testing it this way:

    1. I read such opinion before during my research, I guess it was you who wrote it. And I also read some reactions stating, that QtDesigner produces perfectly valid UI definitions. I'm not judging on that, just I'm ready to give QtDesigner a chance to compare with my decade+ experience with Windows Forms Designer. You warned me :-)
    2. I do (mecanical) engineering and production aps and pack a lot of know-how into them. They often use a lot of GUI widgets. Even though I have plenty of experience with dynamic GUI too, in most cases it's way more convenient to have graphical representation. Imagine you collected a bug list of 10 and you're going to do fixes with little GUI changes in 10 different forms with totally different logic, each with plenty of sections (frames, subframes,...). With GUI managed layouts, you may be done in half an hour, with programatically defined GUI like those (and it's quite real scenario), you have to study first each layout thoroughly and you might spend two days on the job. And I think due to nature of my otherwise simple programming, I have more experience with GUI than probably 98% of coders...
    3. Simply, I have very good graphical memmory. I remember my layouts I made 10 years back - and I really did tons of them. With written code, I hardly remember structure of what I wrote in the morning. I mean I know the logic, I know it's there, but will notorically fail to find the spot I need in any reasonable, direct way.
    4. I am looking for a certain level of productivity on creating GUI, because I do a lot of them. If I couldn't achieve it, I couldn't switch [to PyQt]. That's why the Python and not C++, by the way.

    So I want to give QtDesigner a chance. And I actually expect it will perform quite good, it's here for decades.

  • @Oak77 said in libQt5Core5 missmatch (beginner):

    And I also read some reactions stating, that QtDesigner produces perfectly valid UI definitions.

    One clarification just in case. I guess that @Denni-0 doesn't object the way Qt Designer creates the UI definitions (the XML data written into the .ui file).

    What he does endlessly is to complain about the Python code that it's generated taken that .ui file as input, code generated by tool pyside2-uic, compared to writing the GUI by hand with Python code.

    However, he does endlessly fail to prove with facts such claims.

    So I think you're good to go with your research :-)

  • I also tried to switch to PyQt5 bindings this way:

    import sys
    from PyQt5.QtWidgets import QApplication, uic
    if __name__ == "__main__":
        app = QApplication([])

    ...but I get exactly the same error:

    Traceback (most recent call last):
      File "/home/<user>/Coding/Projects/TestIS/", line 3, in <module>
        from PyQt5.QtWidgets import QApplication, uic
    ImportError: cannot import name 'uic'
    11:04:59: /usr/bin/python3 exited with code 1

    I feel like I'm doing something really basic wrong. But I can find a lot of references to this such syntax with importing 'uic' and really can't find what's wrong.

  • @Oak77

    from PyQt5.QtWidgets import QApplication, uic

    Where did you get idea of from PyQt5/PySide2.QtWidgets import uic from?

    For PySide2:

    Do you want to read and follow approach from ? Essentially

    from PySide2.QtUiTools import QUiLoader
    ui_file = QFile("mainwindow.ui")
    loader = QUiLoader()
    window = loader.load(ui_file)

    For PyQt5:

    It's from PyQt5 import uic, not QtWidgets. See &

    That's to let you load the .ui file dynamically at run-time. If you want to generate a Python class at design-time, there is (command-line tools) pyside2-uic or pyuic5 for PyQt. Or similar, search for these.

    If you want advice on which approach to take, I would say the design-time generation of classes probably gives you easier access to the UI objects created. You have to get used to running the pyuic bit whenever you change the UI in the designer.

    You probably want to make your decision about whether you want to go PySide2 or PyQt5, and stick with it. I don't know what your criteria are.

  • @Oak77

    With PyQt5, first you use the pyuic5 tool that will have been installed at the same time as PyQt5 (assuming you used pip) to convert your .ui file into a python module:

    $ pyuic5 -x mainw.ui -o

    You then import this module into your main application code and use it thus:

    from PyQt5.QtWidgets import QMainWindow
    from mainw import Ui_MainWindow
    class MainWindow(QMainWindow):
        def __init__(self, parent=None, **kwargs):
            super().__init__(parent, **kwargs)
    if __name__=='__main__':
        from sys import argv, exit
        from PyQt5.QtWidgets import QApplication

    Hope this helps :o)

  • "With PyQt5, first you use the pyuic5 tool that will have been installed at the same time as PyQt5...."

    @jazzycamel I believe that is one of possible methods (?). I read through tutorials, posts and books and I'd swear I read explicitely, that those are two different ways to use UI file. Also I'm following tutorials for this method.

    I know I can convert, but I deliberately want to use UI files at this stage, because I'd prefer to use them at design stage. When the particular forms are stable, I might get into habit to export them, if it will help performance noticeably.
    I'm not saying I won't end up using this method as standard later, I'm only learning at this stage.

    I'll try the conversion as per your code and instructionss as another training, it won't hurt me :-).

    I get command-not-found when trying to run:

    pyuic5 -x mainw.ui -o

    So I'm starting to think those two issues are connected.

    Again, I do have PyQt5 installed:

    > pip install --upgrade PyQt5
    Defaulting to user installation because normal site-packages is not writeable
    Requirement already up-to-date: PyQt5 in /home/<user>/.local/lib/python3.6/site-packages (5.14.1)
    Requirement already satisfied, skipping upgrade: PyQt5-sip<13,>=12.7 in /home/<user>/.local/lib/python3.6/site-packages (from PyQt5) (12.7.1)

    ...but the strange "Defaulting to user installation" message might be a clue. My python is in /usr/bin/Python3, my libraries in /usr/lib64/python/ (symlink), but here it looks into user directory /home/<user>/.local/lib/python3.6/site-packages. When I run following command:

    > python -m site
    sys.path = [
    USER_BASE: '/home/<user>/.local' (exists)
    USER_SITE: '/home/<user>/.local/lib/python2.7/site-packages' (doesn't exist)

    ...I think I see the evil: USER_SITE points to different site-packages, from Python 2.7.

    So can I simply do following??

    export USER_SITE=/home/<user>/.local/lib/python3.6/site-packages 

    Does it look like a solution?

  • @Oak77 as a brief summary, there are 3 methods to create your GUIs:

    1. Hand-coded GUI
    2. Tool-coded GUI from .ui file (using pyside2-uic or pyqt-uic)
    3. Loading of .ui file at runtime

  • @Oak77 said in libQt5Core5 missmatch (beginner):

    python -m site

    Before you go any further! Under Linux python executes Python 2. That's why you're seeing all those python2.7 directories. You do not want this at all! Everything you want to do (for Qt) you need to use python3 as the command interpreter, for Python 3!!

  • @JonB You're spot on, but I didn't think it was a problem. Running

    > python
    Python 2.7.17 (default, Jan 24 2020, 15:33:58) [GCC] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
 oposed to:

    > python3
    Python 3.6.10 (default, Jan 16 2020, 09:12:04) [GCC] on linux
    Type "help", "copyright", "credits" or "license" for more information.

    So in terminal, it seems to really run pyuic from 2.7, not 3.6.

    By this time I am totally confused how to make Pythons consistent while maintaining existing dependencies in the OS.

    QtCreator is set to 3.6.10 (Tools --> Options: Python: Interpreters: Make default 3.6.10) as mentioned at the beginnig and the project to run in the same environment (Interpreter = Python 3.6.10).

    What else I can do to get things working?

    I asume that Python 2.7.17 is sitting there due to dependencies of intalled applications.

  • @Oak77
    If you can't find the pyuic5 command itself, but have PyQt5 installed and importable, then run pyuic as a module instead:

    $ python3 -m PyQt5.uic.pyuic -x mainw.ui -o

    For future reference, I always recomend using a seperate virtualenv for each python project you develop. That way you always know where the libraries/tools are and you don't get cross-contamination or version issues.

    Hope this helps :o)

  • "python3 -m PyQt5.uic.pyuic -x mainw.ui -o"

    @jazzycamel - That worked and once I see it, I understand why. Thank you very much.

    I tried one project and set it with virtual environment, but it downloaded some 320 GB of data (for only some dozens of bytes long tutorial). So it can spiral out into significant gigabytes for only few kilobytes I program at the moment, while learning. It seems to me a bit unreasonagle, unless for projects with specific needs. Unless I misunderstood something, which I easily could, at this stage.
    And I also have to get to undertand how Python is set up anyway, if I want to use it, so I'll am testing both ways.

  • @Oak77
    I'm not sure why it would download that much data for a virtualenv, I must have 30 or 40+ on my machine, they are basically throw away tiny things.

    Anyways, I'm glad it worked for you :o)

  • To close this thread, this is final working code:

    import sys
    from PySide2 import QtWidgets
    from PySide2.QtUiTools import QUiLoader
    from PySide2.QtWidgets import QApplication
    class Form(QObject):
        def __init__(self, ui_file, parent=None):
            super(Form, self).__init__(parent)
            ui_file = QFile(ui_file)
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = Form('mainwindow.ui')

Log in to reply