PythonQt is a dynamic Python binding for Qt. It offers an easy way to embed the Python scripting language into your Qt applications.
API documentation is available at: https://mevislab.github.io/pythonqt
PythonQt is distributed under the LGPL 2.1
license.
The build system of PythonQt makes use of a patched version of the LGPL'ed QtScript
generator, located in the generator
directory.
See the LICENSE.LGPL
file in the generator subdirectory for details.
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
See https://code.qt.io/cgit/qt-labs/qtscriptgenerator.git for the original project.
The PythonQt wrappers generated by the generator are distributed under the LGPL
as well.
The integrated preprocessor has been replaced with code from the simplecpp project,
see https://github.com/danmar/simplecpp. It is licensed under the 0BSDL
license,
see the LICENSE
file in the generator/simplecpp directory.
Copyright (C) 2016-2023 simplecpp team
Wrappers are not shipped pre-generated. You must run the generator to
create wrappers for your Qt version. The repository may keep a
single example tree (e.g., generated_cpp_515
) only as a reference.
Building PythonQt requires a couple of steps. Follow these instructions in order to get a correctly built PythonQt runtime and Qt bindings.
First, you need to set a couple of environment variables, which depend on your Python and Qt installation.
-
PYTHON_VERSION
Set the version of your Python interpreter. The syntax is
<major>.<minor>
, e.g.,3.10
. -
PYTHON_PATH
This is the absolute path to the root directory of your Python installation.
-
PYTHON_LIB
The absolute path to the
libs
directory in your python installation$PYTHON_PATH/libs
. -
PYTHON_DIR
The
PYTHON_DIR
is required for non-Windows installations to find thepython-config
executable. This should have the same value asPYTHON_PATH
. -
QTDIR
The absolute path to the root directory of your Qt installation.
-
Configure the generator at the top level
qmake CONFIG+=generator_only CONFIG+=Release PythonQt.pro
-
Build the generator
Use
nmake
for MSVC (Visual Studio; make sure to have the environment variables set for Visual Studio beforehand). Otherwise, usemake
. -
Generate the bindings
Use the generator executable from step 2 to generate the bindings. The location of the generator executable can vary depending on your platform (the subdirectory is named after the current configuration, e.g.,
release
). On Windows, the generator is namedpythonqt_generator.exe
; on all other platforms, it is namedpythonqt_generator
.<generator-executable> qtscript_masterinclude.h build_all.txt
Output location: by default the generator emits to ../generated_cpp
(relative to the build). You can override this with:
qmake PYTHONQT_GENERATED_PATH=/abs/path/to/generated_cpp
CONFIG+=generator_only
: build only the wrapper generator.CONFIG+=exclude_generator
: build everything except the generator.
Use these to (1) build the generator, (2) run it to produce generated_cpp
, then (3) build the rest without rebuilding the generator.
Next, build the runtime (and extensions) without the generator.
-
Configure at the top level
qmake CONFIG+=Release CONFIG+=exclude_generator PythonQt.pro
-
Build
Use
nmake
for MSVC (Visual Studio; make sure to have the environment variables set for Visual Studio beforehand). Otherwise, usemake
.
The build will fail early if wrappers are missing from
../generated_cpp
or the path specified viaPYTHONQT_GENERATED_PATH
.
After all these steps, you should now have a fully working PythonQt runtime and Qt bindings for your Python/Qt installation 🎉.
It is possible to build PythonQt with MinGW on Windows instead of using MSVC.