1

Running on Windows 10 64 bit and Python 3.7.4 (no Anaconda), the basic script from Terminate PyQt Application

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize    

class HelloWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(640, 480))    
        self.setWindowTitle("Hello world") 

        centralWidget = QWidget(self)          
        self.setCentralWidget(centralWidget)   

        gridLayout = QGridLayout(self)     
        centralWidget.setLayout(gridLayout)  

        title = QLabel("Hello World from PyQt", self) 
        title.setAlignment(QtCore.Qt.AlignCenter) 
        gridLayout.addWidget(title, 0, 0)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = HelloWindow()
    mainWin.show()
    sys.exit( app.exec_() )

does not exit when starting from Spyder. The IPython console simply "idles", but never returns. Running the script from the command prompt (i.e. 'python script.py') works OK.

Switching back to a fresh install of Python 3.7.2, everthing works as expected. The IPython version is in both cases 7.7.0.

In both cases (3.7.2 and 3.7.4) all modules including Spyder had been installed via pip.

Any idea why that is? Is it a Spyder related issue?

Nick is tired
  • 6,860
  • 20
  • 39
  • 51
Clemens
  • 313
  • 4
  • 15
  • @mishsx Code formatting is meant for code, please don't edit to change version numbers, operating system/program names etc. to be formatted as code, it's unnecessary and unreadable – Nick is tired Aug 16 '19 at 16:34
  • (*Spyder maintainer here*) Please read [our guide](https://github.com/spyder-ide/spyder/wiki/How-to-run-PyQt-applications-within-Spyder) on how to run PyQt applications in Spyder. – Carlos Cordoba Aug 17 '19 at 10:22
  • @CarlosCordoba: If I set the backend on 3.7.2 to Automatic, as suggested, the same problem (no exit) occurs. Choosing the Inline option, some things are obscured, like transparency of icons, but the program exits fine. – Clemens Aug 17 '19 at 11:05
  • 1
    @CarlosCordoba: Using 3.7.4, following your guide *does* work. Setting the backend to automatic solves it. So the actual problem seems to be why setting it to Automatic in 3.7.2 creates the issue. – Clemens Aug 20 '19 at 09:48
  • Sorry, I have no idea why things fail for that version. – Carlos Cordoba Aug 20 '19 at 11:09

1 Answers1

1

Keeping the Graphics Backend as not "Inline" is creating this problem.

Either change the graphics backend as,

Tools -> Preferences --> IPython Console -> Graphics --> Graphics Backend as Inline

Or Restore the default settings of the Spyder Environment. Which can be done by,

Tools -> Preference --> Reset to Defaults.