Important: Please read the Qt Code of Conduct -

Building PySide2 against non-gui Qt

  • Hello there!

    I'm trying to build PySide2/Shiboken2 against a minimized Qt installation, that is, a Qt installation that eschews all modules not necessary for our purposes, which are basically all GUI modules.

    However, when I try to run the script from PySide's Git repo, I always end up with the following error message:

    $ python3 build --qmake=/path/to/my/qmake --build-tests --ignore-git --parallel=8 --skip-modules=Gui,Declarative,Widgets,Location,Sensors,GraphicalEffects,QuickControls,WebSockets,QuickControls2,Qml,UiTools,Help,OpenGL,OpenGLFunctions,QuickWidgets,Svg,Quick,X11Extras,Test,Sql,PrintSupport
    Project ERROR: Unknown module(s) in QT: gui
    Traceback (most recent call last):
      File "", line 286, in <module>
        from build_scripts.main import get_package_version, check_allowed_python_version
      File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/", line 289, in <module>
        qtinfo = QtInfo(QMAKE_COMMAND)
      File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/", line 61, in __init__
      File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/", line 199, in _init_properties
      File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/", line 184, in _get_other_properties
      File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/", line 208, in _get_qmake_mkspecs_variables
        lines = [s.strip() for s in qmake_output.splitlines()]
    AttributeError: 'NoneType' object has no attribute 'splitlines'

    The same message appears when I try to build a different project that makes no use of GUI components and disables the GUI module in it's QMake project file using QT -= gui. Yet, somehow, QMake seems to be looking for it, if I understand the error message and my earlier Google results correctly.

    I'm building on Fedora 31, Qt 5.14.1 was build on the same machine, PySide 2 version checked out from repo is also 5.14.1. There are no spaces or similar in the path to the QMake installation (which, due to us using Conan as a package manager, is /home/<user>/.conan/data/qt/5.14.1/<client>/stable/package/<package-hash>/).

  • Lifetime Qt Champion


    I am not sure it is currently supported. I'd recommend bringing that question to the PySide mailing list. You'll find there PySide2 developers/maintainers. This forum is more user oriented.

  • This is the bit it's failing:

        def _get_qmake_mkspecs_variables(self):                                                            
            # Create empty temporary qmake project file.                                                   
            temp_file_name = 'qmake_fake_empty_project.txt'                                                
            open(temp_file_name, 'a').close()                                                              
            # Query qmake for all of its mkspecs variables.                                                
            qmake_output = self._get_qmake_output(['-E', temp_file_name])                                  
            lines = [s.strip() for s in qmake_output.splitlines()]  

    That means calling qmake failed on the fake_empty_project
    Can you maybe share the whole output of the build process? Then we can check if something is wrong with the Qt detection.

  • Quick update, we continued the discussion on the PySide2 Gitter room, and since QtSQL has dependencies with QtWidgets, OP will try to have a local qtbase without QtSQL and hence without the graphical dependencies, because QtGui was not present in the installation.

    The qmake step that produced the error is that we create an empty .txt file to use qmake -E empty.txt and get information from the Qt installation and that command was complaining that GUI was not found.

  • Banned

    Interesting nice to know.

    Although I am not sure why anyone would use QtSql since straight python to a database works just fine and the front-end Gui ought to be completely divorced from your back-end data source in almost every application I can think of. This is because the benefits to using this methodology are well worth the implementation and further implementing and maintaining this methodology is often a lot easier and safer than tightly tying the front-end directly to the back-end which is what would occur, if understand its use purpose correctly, when you use QtSql

  • I've been working on this and actually got Shiboken and PySide to build, though I could only build with the Core, Xml and Network modules included (including any of the other modules we depend upon in our main application would lead to error messages about QtGui or QtWidgets not being found by CMake). Haven't testet them with our bindings, yet, as we seem to pull QtGui into them at some subproject.

    That said, I needed to patch the pyside2-tools project. As it turns out, pylupdate includes qapplication.h and qmessagebox.h in metatranslator.cpp - to display a message box in case of an error (using a global variable called qApp that I couldn't trace down to decide whether or not to use the message box or stdout).

    I'll mark this as resolved as my original problem has been fixed. Thanks again to all who helped!

    EDIT: For the record, these are my changes in the pyside2-tools subrepo:

    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index ce65750..179ce23 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -55,12 +55,14 @@ else()
         set(DESIGNER_PATH "${TOOLS_PATH}/designer${EXE_EXT}")
    -install(FILES "${UIC_PATH}"
    -        DESTINATION bin
    -        PERMISSIONS
    +if (EXISTS ${UIC_PATH})
    +    install(FILES "${UIC_PATH}"
    +            DESTINATION bin
    +            PERMISSIONS
    +            WORLD_EXECUTE WORLD_READ)
     install(FILES "${RCC_PATH}"
             DESTINATION bin
    diff --git a/pylupdate/CMakeLists.txt b/pylupdate/CMakeLists.txt
    index a46608c..3f67fe7 100644
    --- a/pylupdate/CMakeLists.txt
    +++ b/pylupdate/CMakeLists.txt
    @@ -12,9 +12,7 @@ translator.cpp
     set(lupdate_MOC_HEADERS translator.h)
     qt5_wrap_cpp(lupdate_MOC_OUTFILES ${lupdate_MOC_HEADERS})
    @@ -24,15 +22,11 @@ include_directories(pyside2-lupdate
    -                    ${Qt5Gui_INCLUDE_DIRS}
    -                    ${Qt5Widgets_INCLUDE_DIRS}
    -                      ${Qt5Gui_LIBRARIES}
    -                      ${Qt5Widgets_LIBRARIES}
     install(TARGETS pyside2-lupdate RUNTIME DESTINATION bin)
    diff --git a/pylupdate/metatranslator.cpp b/pylupdate/metatranslator.cpp
    index 8a8ac8e..2588895 100644
    --- a/pylupdate/metatranslator.cpp
    +++ b/pylupdate/metatranslator.cpp
    @@ -25,10 +25,8 @@
     #include "metatranslator.h"
    -#include <qapplication.h>
     #include <qbytearray.h>
     #include <qfile.h>
    -#include <qmessagebox.h>
     #include <qtextcodec.h>
     #include <qtextstream.h>
     #include <qxml.h>
    @@ -204,11 +202,7 @@ bool TsHandler::fatalError( const QXmlParseException& exception )
             const QString msg = QString::asprintf( "Parse error at line %d, column %d (%s).",
                          exception.lineNumber(), exception.columnNumber(),
                          exception.message().toLatin1().data() );
    -        if ( qApp == 0 )
    -            fprintf( stderr, "XML error: %s\n", msg.toLatin1().data() );
    -        else
    -            QMessageBox::information(0,
    -                                      QObject::tr("Qt Linguist"), msg );
    +        fprintf( stderr, "XML error: %s\n", msg.toLatin1().data() );
         return false;

Log in to reply