
Embedding the Python Interpreter in a Qt Application - istotex
https://ubuverse.com/embedding-the-python-interpreter-in-a-qt-application/
======
FigBug
I looked at doing this several years ago on Windows and I seem to recall that
Python had a lot of global state. So you could only have one instance of the
Python VM and therefore only Python script running at once. Is this still the
case?

In the end, for me, it was easier to share file formats between the C++ and
Python and run the Python scripts out of process.

~~~
drdaeman
There are sub-interpreters: [https://docs.python.org/3/c-api/init.html#sub-
interpreter-su...](https://docs.python.org/3/c-api/init.html#sub-interpreter-
support)

~~~
_wmd
Subinterpreters still share a lock and suffer from compatibility issues with C
extension modules as the module interface only exports a very primitive notion
of per-subinterpreter state, they're pretty much not all that safe to use
unless you have a very constrained environment

------
douche
If you have the luxury of using .NET, embedding IronPython is considerably
easier, in my experience. A while back I was fooling around writing a game
engine with python scripting support, and it was pretty slick to get going
with.

~~~
denfromufa
In .NET you can also embed CPython​ using pythonnet:

[https://github.com/pythonnet/pythonnet](https://github.com/pythonnet/pythonnet)

------
Liuser
Piggy backing off this a little, in a similar vain I recently embedded Python
in a macOS app (approved by the store) which was a bit of a pain to do. I
documented the process as well since I couldn't find a full fledged tutorial
on it.

[https://medium.com/python-pandemonium/embedding-a-python-
app...](https://medium.com/python-pandemonium/embedding-a-python-application-
in-macos-d866adfcaf94#.1396ywujo)

------
deft
Something like this can be (could be?) done with a BlackBerry 10 application.
I developed a hackernews client with a python backend and Qt QML frontend.
Didn't involve embedding the interpreter as BB10 shipped with python3.2

[https://bitbucket.org/microcode/blackberry-
py/](https://bitbucket.org/microcode/blackberry-py/) [http://blackberry-
py.microcode.ca/](http://blackberry-py.microcode.ca/)

------
srean
Has the embedding story improved for Python 3.* ? Whereas extending Python is
easy enough, embedding has not been that convenient. Tcl, Guile, Lua do a far
better job.

If anyone has drops of wisdom on how to run an embedded Python as a filter or
an iterator I would be super interested to know.

------
fernly
What'r the choice points between doing this, and building a Qt app using PyQt
(or PySide)? Again all the logic is in Python, no C++ whatever. And use
PyInstaller or cxFreeze to make a standalone app for distribution.

