spyder-ide / spyder-kernels

Jupyter Kernels for the Spyder console
MIT License
39 stars 40 forks source link

TypeError on initialization of PyQt5 QtWidgets.QApplication #276

Open casimir7 opened 3 years ago

casimir7 commented 3 years ago

Hello spyder-kernels team. Thanks for your work! I stumbled across the following

Problem:

On my system: Fedora 33, Python 3.9 Spyder 4.1.5 PyQt5 5.15.0,

I cannot instantiate QApplication in Spyder. As a test case, run the following code

import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
def window():
   app = QApplication(sys.argv)
   w = QWidget()
   b = QLabel(w)
   b.setText("Hello World!")
   w.setGeometry(100,100,200,50)
   b.move(50,20)
   w.setWindowTitle("PyQt5")
   w.show()
   sys.exit(app.exec_())
if __name__ == '__main__':
   window()

On execution in the IPython Shell I get the following error:

 File "/usr/lib/python3.9/site-packages/spyder_kernels/customize/spydercustomize.py", line 160, in __init__
    super(SpyderQApplication, self).__init__(*args, **kwargs)

TypeError: super(type, obj): obj must be an instance or subtype of type

The same code runs on a terminal using the standard python interpreter without problems.

Solution:

The error can be fixed by changing line 160 of spydercustomize.py from super(SpyderQApplication, self).init(*args, *kwargs) to super().init(args, **kwargs).

impact27 commented 3 years ago

That is strange. Maybe you have several versions of PyQt5 installed? Unfortunately we can't use super() because of python 2