How to fix PySide2 does not show the main window

--

On Apple Silicon — x86 with Rosetta2

Often, when working with PySide2 on macOS Monterey or Ventura with Apple Silicon, the main window is not shown, even though the execution of our python code does not seem to give any problems and an icon representing the interface itself appears.

The PySide window is not displayed

I’m working with the following setup, but this solution might be extended to different cases:

  • Apple Silicon M1 (Macbook Pro 2020 13 inches)
  • macOS Monterey 12.6
  • x86 Miniconda installation
  • python3.9
  • PySide2 from conda-forge

When this happens, you’ll have to shut down your application. Luckily, a quick fix to this bug exists and is as simple as changing a global variable:

import os
os.environ['QT_MAC_WANTS_LAYER'] = '1'

You’ll have to do so in the main script of your application.

--

--

Marco Sanguineti

Graduated in Mechanical Engineering, I work in the world of AI, Deep Learning and Software Development. Passionate about Technology, Videogames and AI.