Search code examples
pycharmpyside2qapplication

'NoneType' error when calling QApplication(sys.argv), pycharm


I'm new to PySide2 and I'm facing this issue while creating super simple window with PySide2 and Pycharm: Qapplication() error :'NoneType'; both with sys.argv as argument and without any argument the error occur. I'm using mayapy.exe as python interpreter from maya 2022, I'm wondering if someone could give some advice to setup properly Pycharm for PySide2. this is the code i try to run:

from PySide2.QtWidgets import QApplication, QWidget
import sys

class Window(QWidget):
    def __init__(self):
        super(Window, self).__init__()

        self.setWindowTitle("PySide2 app")
        self.setGeometry(300,300,300,300)

app = QApplication()
myWindow = Window()
myWindow.show()
app.exec_()
sys.exit(0)

-----------
Error
-----------

Traceback (most recent call last):
  File "E:/QtDesigner/pyside2_app.py", line 11, in <module>
    app = QApplication()
TypeError: 'NoneType' object is not callable

Thanks for your help!


Solution

  • The problem was related to the mayapy.exe python interpreter that return a 'None Type' class while calling QApllication( ) with PySide2 module. I found this solution that works for me:

    • install python 3.10 (I assume that version doesn not matter)

    • add new python interpreter for the project ( File->Settings->Project : MyProject -> Python Interpreter -> (settings icon) ->Add.. -> Base interpreter: C:\Users\User\AppData\Local\Programs\Python\Python310\python.exe ).

    • add Pyside2 package in the settings of the Python interpreter inside PyCharm ( icon '+' under settings -> Python interpreter-> Package). Hope this could be helpful.