I am working for the first time towards the implementation of a very simple GUI in
PyQt5, which embeds a
matplotlib plot and few buttons for interaction.
I do not really know how to work with classes so I’m making a lot of mistakes, i.e. even if the functionality is simple, I have to iterate a lot between small corrections and verification.
For some reason I would like to debug, however, the whole process is made much, much slower by the fact that at any other try, the python kernel dies and it needs restarting (all done automatically) several times.
That is, every time I try something that should last maybe 5 secs, I end up spending a minute.
Anybody know where to look to spot what is causing these constant death/rebirth circles?
I have been using
spyder for some time now and I never experienced this behaviour before, so I’m drawn to think it might have to do with
PyQt, but that’s about how far I can go.
This issue is tracked here
You can learn all the details there, but in a nutshell when running from inside
spyder – which itself is a
QApplication, the main loop should read:
if __name__ == '__main__': import sys from PyQt5 import QtWidgets fig1 = Figure() if not QtWidgets.QApplication.instance(): app = QtWidgets.QApplication(sys.argv) else: app = QtWidgets.QApplication.instance() main = Main() main.addmpl(fig1) main.show() sys.exit(app.exec_())
if/then check on the existence of a
QApplication avoids a segmentation fault which happens if one tries to launch multiple instances at one time, as explained here
I had a similar problem and found that my application only worked when the graphics settings inside Spyder are set to inline. This can be done at Tools -> Preferences -> IPython console -> Graphics, now change the Backends to inline.
Hope this helps.