0

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!

simogerr
  • 1
  • 2
  • How are you running the script? Did you try to run it directly from a terminal or command prompt? You mentioned the maya interpreter, are you using it or the standard one? – musicamante Sep 16 '22 at 17:09
  • @musicamente Actually i'm try to run it in the Run tool Window of PyCharm and I suppose it lunch the code in the terminal, regarding the interpreter i'm using the standard one (inside bin, in the Maya versions folder C:\Program FIles\Autodesk\Maya2022\bin\mayapy.exe) – simogerr Sep 19 '22 at 08:30
  • I don't think this is the cause of your problem but QApplication needs to be called with an argument, usually sys.argv or an empty list `QApplication([])` – Alexander Sep 19 '22 at 08:35
  • @Alexander I tried it but unfortunately it does not work, i recently read that could be a problem on the mayaDevKit PySide2 module but, I dont really understand why it coul be a problem and also i tried to exclude the path of the dev kit( or at least I assume i exclude it) but the problem still occur. the path of the module is C:\Program Files\Autodesk\Maya2022\devkit\other\Python27\pymel\extras\completion\py\Pyside2 – simogerr Sep 19 '22 at 09:10
  • IDK I have never used pycharm or maya – Alexander Sep 19 '22 at 09:50
  • I found this solution: - install python 3.10 - add new PyCharm 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 ). Than Add Pyside2 package in the settings of the Python interpreter ( icon '+' under settings -> Python interpreter->Package). Hope this could be helpful. – simogerr Sep 19 '22 at 14:41

1 Answers1

0

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.

simogerr
  • 1
  • 2