I have an application that can be extended using Python macros. As python is not often used, for every macro, I initialize the python interpreter, run the macro, and then finalize the interpreter.
Everything works just fine, with the exception of PyQt5: after the end of the first macro, all classes disappear from the PyQt5 modules. I guess this is a problem with static variables and the PyObject being destroyed when finalizing. But is there something to do beside never killing the Python interpreter?
Here is the code of my macro:
from PyQt5 import QtWidgets
def initialize(X, Y, Z, printed, parent):
X, ok = QtWidgets.QInputDialog.getDouble(parent, "Select radius", "X = ", float(X), 0, 10)
if not ok:
return False
return X, X, X, printed
On first run, I have the dialog box, but on the any other run I get the error:
Traceback (most recent call last):
File "[...]/macros/TestBlur.py", line 13, in initialize
AttributeError: 'module' object has no attribute 'QInputDialog'
Edit: Maybe another way to see this is: is there a way to explicitely instantiate all the classes for PyQt5, in the same way you have to call import_array
to initialize the numpy
library?