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
setup.py
script from PySide's Git repo, I always end up with the following error message:$ python3 setup.py 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 "setup.py", 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/main.py", line 289, in <module> qtinfo = QtInfo(QMAKE_COMMAND) File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/qtinfo.py", line 61, in __init__ self._init_properties() File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/qtinfo.py", line 199, in _init_properties self._get_other_properties() File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/qtinfo.py", line 184, in _get_other_properties self._get_qmake_mkspecs_variables() File "/home/<user>/Projekte/<client>/pyside-setup/build_scripts/qtinfo.py", 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>/
). -
Hi,
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 useqmake -E empty.txt
and get information from the Qt installation and that command was complaining that GUI was not found. -
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
andqmessagebox.h
inmetatranslator.cpp
- to display a message box in case of an error (using a global variable calledqApp
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}") endif() -install(FILES "${UIC_PATH}" - DESTINATION bin - PERMISSIONS - OWNER_EXECUTE OWNER_WRITE OWNER_READ - GROUP_EXECUTE GROUP_READ - WORLD_EXECUTE WORLD_READ) +if (EXISTS ${UIC_PATH}) + install(FILES "${UIC_PATH}" + DESTINATION bin + PERMISSIONS + OWNER_EXECUTE OWNER_WRITE OWNER_READ + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ) +endif() 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 ) find_package(Qt5Core) -find_package(Qt5Gui) find_package(Qt5Xml) -find_package(Qt5Widgets) set(lupdate_MOC_HEADERS translator.h) qt5_wrap_cpp(lupdate_MOC_OUTFILES ${lupdate_MOC_HEADERS}) @@ -24,15 +22,11 @@ include_directories(pyside2-lupdate ${CMAKE_CURRENT_SOURCE_DIR} ${Qt5Xml_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} - ${Qt5Gui_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} ) target_link_libraries(pyside2-lupdate ${Qt5Core_LIBRARIES} ${Qt5Xml_LIBRARIES} - ${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; }