A python GUI project made with pyside2 on macOS Big Sur sometimes does not show the main window. You can see the icon in the tray:
But you see no window and have to force quit the app. The problem can be solved by adding an environment variable.
Put this before creating the main window:
import os os.environ['QT_MAC_WANTS_LAYER'] = '1'
import sys from PySide2.QtWidgets import QApplication from PySide2.QtWidgets import QLabel import os os.environ['QT_MAC_WANTS_LAYER'] = '1' app = QApplication(sys.argv) label = QLabel("<center> <h1>I must have left my house at eight,<br />because I always do.</h1> </center>") label.show() app.exec_()
And boom! The window is shown:
In pyside6 the Layer-backing is always enabled. If you add the code os.environ['QT_MAC_WANTS_LAYER'] = '1'
in a pyside6 project, you get the
following warning:
Layer-backing is always enabled. QT_MAC_WANTS_LAYER/_q_mac_wantsLayer has no effect.
Add the line os.environ['QT_MAC_WANTS_LAYER'] = '1'
in a pyside2 project or
upgrade to pyside6.