Qt for Python/GettingStarted
Considerations before starting
PySide2 supports Python 2 (recommended: 2.7 onwards, Compatibility module six installed) and Python 3 (recommended: 3.5 onwards).
On Windows, it is recommended to use Python 3 and build with MSVC2015. Python 2 requires building with MSVC2008.
Currently, only Qt 5.6 is supported. Qt needs to be build with the QtXmlPatterns module.
Development happens in the dev branches of the repositories. The top level repository has several submodules:
- sources/shiboken2: Shiboken Parser
- sources/pyside2: PySide 2
- sources/pyside2-examples: Examples
- sources/pyside2-tools: uic, rcc
- wiki: Wiki
Contributions follow the standard process.
Building requires CMake.
It is helpful to have debug binaries and/or symbols for Python available. On Windows, this is done choosing Customized Installation when installing python and ticking the respective check boxes. On Linux, debug packages can be installed in addition. For Ubuntu, the packages python3-dbg, libpython3-dbg provide a debug binary python3-dbg.
It is also recommended to use a Virtual Environment for testing to be able to always start from a clean base and avoid issues with write permissions in installations.
On Linux, the command
virtualenv -p /usr/bin/python3-dbg testenv
creates a Virtual Environment named testenv for debugging purposes. On Windows, an installation step may be required:
python -m pip install virtualenv python -m virtualenv testenv
The Virtual Environment is activated by
The script setup.py in the top level repository is used to build and install the PySide2 package. It takes a mode argument (build or install) and several options.
- --qmake=<binary> Path to qmake of the Qt library to be used
- --cmake=<binary> Path to cmake
Further options of interest:
- ---ignore-git: Prevents setup.py from cloning and checking out the submodules.
- --build-tests: Creates a directory containing the tests along with some helper packages
- --debug: Build in Debug mode
- --openssl: Path to OpenSSL
A typical invokation looks like:
setup.py install ---ignore-git --build-tests --qmake=../bin/qmake --cmake=/usr/bin/cmake
A successful build can be tested by running an example:
Building the Documentation
This is currently unexplored terrain.
- The sources are in pyside2/doc
- libXML2 and libXSLT should be present when building PySide2 (Ubuntu: apt-get install libxml2-dev libxslt1-dev)
- sphinx should be installed (pip install sphinx)
- qdoc3 is used to generate it
Using Qt Creator as a project explorer
Qt Creator 4.0+ can be used to open the PySide and Shiboken CMakeLists.txt files as projects, and thus provide usual IDE features for developing PySide - project file navigation, code completion (C++ only), following symbols under cursor (C++ only), syntax highlighting, locator usage, debugging, etc.
Currently there is a limitation that Shiboken has to be built first using the terminal, because the installed shiboken CMake packages will have to be specified for the PySide project in Qt Creator.
The steps for opening the projects in Qt Creator are:
- Open pyside-setup/sources/shiboken2/CMakeLists.txt, and specify a 5.6 Qt Kit to be used
- Build the project as usual (by pressing the build icon for instance)
- Open pyside-setup/sources/pyside2/CMakeLists.txt, and specify the same 5.6 Qt Kit
- Go to projects tab, and under the Build / CMake section find the Shiboken2_DIR setting. You have to specify the path to the folder where the Shiboken CMake package was installed when you compiled Shiboken from the terminal
- An example path under MacOS is /Users/user/Dev/pyside2-setup/pyside_install/py2.7-qt5.6.1-64bit-debug/lib/cmake/Shiboken2-2.0.0. The path has to be adjusted depending on the user folder name, the version of python and qt, etc
- (Optional) On MacOS you also have to set the ALTERNATIVE_QT_INCLUDE_DIR setting to the Qt kit include path (e.g. /Users/user/Dev/qt56_source/include)
- Apply the CMake configuration changes (by pressing the button), and you should be able to build PySide
Now you can use the project explorer to look through the source cpp files, python files, use the locator feature to open files and file classes / methods, and other features that Qt Creator provides.