I am writing an app using PyQt6, but when it's time to open a simple MainWindow I get the following error:
qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
zsh: abort python main.py
I tried to run suggested solutions on the web (reinstalling Qt and installing opencv-python-headless) without success. Could you help me to figure out what is going on?
Thanks!
Stefano
macOS Ventura 13.4.1 python 3.11.3
I solved first looking for the file libqcocoa.dylib and finding its full path (in my case /Users/<user>/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins/platforms
, but this will depends on what you are using: PyQt5, PyQt6, or simply Qt).
I then updated the variable QT_PLUGIN_PATH:
export QT_PLUGIN_PATH=/Users/xizg0003/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins
To make the change permanent, I located the file qt.conf (in my case located in /Users/<user>/anaconda3/bin
) and added the plugin directory path to the file, just below [Paths]:
Plugins = /Users/<user>/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins