3

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Michele Ancis
  • 1,265
  • 4
  • 16
  • 29
  • (*Spyder developer here*) Please open an issue in our issue tracker with the code you're trying to run so we can better understand what you're doing and help you to fix it, or fix something in Spyder if necessary. This is not the right place to continue this discussion, sorry. – Carlos Cordoba Apr 10 '17 at 19:58
  • Nw thanks Carlos. Will do but I have strong limits when it comes to posting code, because of my Company's policies. I'll try and do my best. Issue tracker == git? – Michele Ancis Apr 10 '17 at 20:58

2 Answers2

3

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_())

The 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

Community
  • 1
  • 1
Michele Ancis
  • 1,265
  • 4
  • 16
  • 29
1

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.