PySide6 Bindings Build Guide¶
This document describes how to build the SARibbon PySide6 bindings (PySideSARibbon) from source, using the official Qt Shiboken6 generator.
Unlike the PyQt bindings (based on SIP), the PySide6 bindings use Shiboken6 + CMake, but share the same C++ source code.
Comparison with PyQt Bindings¶
| Aspect | PyQt (SIP) | PySide6 (Shiboken6) |
|---|---|---|
| Binding description | .sip files |
typesystem_saribbon.xml |
| Build system | pyproject.toml + sip-build | CMakeLists.txt + CMake |
| Enum handling | %MappedType to int |
<enum-type> native Python Enum |
| Resource handling | qmake RESOURCES | CMake qt_add_resources |
| Module name | PyQtSARibbon.saribbon | PySideSARibbon.saribbon |
Prerequisites¶
| Software | Version | Description |
|---|---|---|
| Python | 3.9 or higher | 3.10+ recommended |
| PySide6 | 6.5 or higher | Official Qt Python bindings |
| shiboken6-generator | matching PySide6 | Shiboken6 binding generator |
| Qt6 Dev Package | 6.5 or higher | Required: Qt6 C++ headers and CMake config |
| CMake | 3.22 or higher | Build system |
| Ninja | latest | Recommended build backend |
| C++ Compiler | MSVC 2019+ / GCC 9+ | Native code compiler |
Important
The PySide6 pip package does not include full Qt6 C++ development headers
(such as qglobal.h). You must install Qt6 development package via the
Qt Online Installer or aqtinstall.
Install Qt6 Development Package¶
Option A: Qt Online Installer (Recommended)¶
Download from qt.io and install Qt 6.7+ for MSVC 2019 64-bit.
Option B: aqtinstall¶
1 2 | |
Qt6 path will be D:\Qt6\6.7.3\msvc2019_64.
Installing Dependencies¶
1. Install Python Dependencies¶
1 | |
Verify:
1 2 | |
2. Verify Qt Installation¶
1 | |
3. Install CMake and Ninja¶
1 | |
4. Configure Compiler¶
Windows (MSVC)¶
1 | |
Linux (GCC)¶
1 | |
Build Steps¶
1. Clone Source Code¶
1 2 | |
2. Build PySide6 Bindings¶
Option A: Build Script (Windows Recommended)¶
1 | |
With explicit paths:
1 | |
The script automatically:
- Checks PySide6 and shiboken6-generator installation
- Initializes MSVC environment
- Runs CMake configure and build
- Installs to site-packages
Option B: Manual CMake Build¶
1 2 | |
With explicit Qt path:
1 | |
3. Install Module¶
1 | |
Verify Installation¶
1 | |
Example¶
1 | |
Troubleshooting¶
shiboken6-generator not found¶
Error: Could not find shiboken6 executable
1 | |
Note: The current CMakeLists.txt does not use
find_package(Shiboken6Tools). Instead, it manually locatesshiboken6.exe, library files, and include directories. PySide6 6.8.x does not includeShiboken6ToolsConfig.cmake, so the oldfind_package(Shiboken6Tools)approach is no longer used.
Qt headers not found¶
Error: fatal error: QtWidgets: No such file or directory
1 | |
Compiler not found¶
Error: Cannot run compiler 'cl'
Use the Visual Studio Developer Command Prompt.
DLL load failed¶
Error: ImportError: DLL load failed while importing saribbon
Ensure PySide6 and Qt DLLs are in PATH, or copy Qt DLLs to site-packages.
PyQt / PySide6 conflict¶
Use a virtual environment to isolate PyQt and PySide6:
1 2 3 | |
Qt class constructors crash when accessed indirectly¶
Update: After thorough investigation, this issue is NOT caused by shiboken type registration conflicts. Indirect access to Qt classes works perfectly fine. The original crash was caused by file encoding issues (mixed BOM/CRLF/LF). Ensure Python source files use UTF-8 without BOM and LF line endings.
PySide6 and Qt6 version mismatch¶
Symptom: Build succeeds but crashes at runtime, or qjsonparseerror.h: No such file or directory error during build.
Root cause: The Qt header version in the PySide6 pip package must match the system-installed Qt6 C++ development package version. For example, PySide6 6.8.3 requires Qt 6.8.3 dev package.
Solution: Ensure version match:
1 2 3 4 5 | |
Themes and icons not showing at runtime¶
Symptom: Window starts with no QSS theme styling, icons missing, console shows can not load build in ribbon theme.
Root cause: The RCC static initializer for Qt resource files (.qrc) is stripped by MSVC linker's /OPT:REF optimization. When qt_add_resources output is placed in the static library saribbon_lib, no code explicitly references the qrc-generated symbols, so the entire qrc object file is removed from the final .pyd.
Solution: Ensure qt_add_resources output is compiled into the final MODULE target (.pyd), not the static library. The current CMakeLists.txt handles this correctly:
1 2 3 | |
Next Steps¶
See Use Python Bindings for how to use SARibbon in Python.