Plugin for QtCreator that allows to run extensions written in Python
THIS REPOSITORY HAS BEEN MOVED TO THE OFFICIAL QT REPOSITORY
This plugin for QtCreator makes it possible to extend the QtCreator by writing Python extensions.
These extensions consist of a directory containing a main.py
and any other Python files necessary.
They can be shared as zip archives, installed and managed through the included extension manager
(which is a Python extension itself) and thus allow the QtCreator to be easily extended with
custom functionality.
WARNING: This is a first draft / proof of concept and only offers very limited functionality. There will still be many bugs and so far the project has only been tested on Linux.
This repository contains the following:
examples
folder. These can be installed manually, see theexamples/README.md
for more information.Note that this process has so far only be tested on Linux. The plugin itself has only been tested with Python 3.5 and 2.7.12 and QtCreator 4.7.82.
Before you can compile and install the PythonExtensions plugin, you need to install PySide2 for the version of Python you plan to use. This is necessary, as the plugin uses the system installed Python (or the Python installed in your virtual env, if you have one set up) and it's packages. You will also need to build your own version of QtCreator and require a Qt installation. (This project has so far only been tested with Qt5.11.0.)
To obtain the required Qt version, you can either build Qt yourself, or use the installer provided on the Qt website.
To install PySide2 please refer to their installation instructions. When installing PySide2, make sure Shiboken is installed alongside, as it will be necessary for compiling the plugin. (Shiboken is the binding generator used by and originally developed for PySide2.)
WARNING: This project depends on two recent patches to Shiboken, one of which has not yet passed code review. These patches are:
Make sure your version of Shiboken has both of these patches. Otherwise, you will encounter errors when parsing / compiling this project. To get these patches, you will probably need to build Shiboken from source.
To build QtCreator, which is necessary for building the plugin, please refer to their build instructions.
Once all dependencies are installed, you can go ahead and build the plugin itself. To do this (in
the best case) all you will have to do is run the following commands in the plugins/pythonextensions
directory:
$ path/to/your/qmake
$ make
After this, the plugin should be installed into the QtCreator version you built in the previous
steps. If this worked, you can now go ahead and check out the examples
folder and play with the
provided example Python extensions.
Notice that depending on your configuration, you may need to add Clang to your library paths for Shiboken to run. Achieve this by running the following before building the plugin:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/clang/lib
You may need to expose your QtCreator sources like this:
export QTC_SOURCE=/path/to/your/qt-creator
export QTC_BUILD=/path/to/your/qt-creator
NOTICE: This plugin generates a few debug messages and potential warnings. Any Python extension that is installed might also write output to stdout. To see these messages, you can execute QtCreator from your terminal by running the executable there.
There are several things you might want to try:
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/your/libclang/lib
set(CMAKE_PREFIX_PATH "/path/to/your/qt5/5.11.0/gcc_64")
in the file sources/pyside2/CMakeLists.txt
in the PySide project.pythonextensions.pro
and change the hard-coded fall-back paths you find there toIf none of the above suggestions fix your problem, I am afraid you will have to find a solution for yourself. If that happens and you find a fix, please contact the developers, so that it can be included in this list (or in the build system).
In a nutshell, this project generates Python bindings for the QtCreator using Shiboken and then executes python scripts it finds in a bespoke directory.
The following process allows the plugin to work:
python
, the first directory found is the Python extension directory.
setup.py
. If it does, this setup script ismain.py
. This file is the extensions entry point and is executed by the C++ plugin.When executed, the Python extensions can import any modules / packages installed for the system Python or found in their own directory. While the C++ plugin takes some precautions to isolate the Python extensions when executed, they are still all run in the same Python instance, which means that they are not completely isolated. However, so far this did not turn out to be a problem.
For a more detailed description, please refer to the documentation in docs
.