Reputation: 1279
I'm experimenting a little bit with Qt. I have successfully written a small app which works fine on my Windows 8.1 Laptop. Now I installed XCode and Qt and copied the project folder to my MacBook. The application compiles fine on my Mac but when I wan't to run it via Qt Creator I'm getting the following errors:
[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. Reinstall application may fix this problem.
I have read that the tool macdeployqt
is needed when I want to deploy the app to other PCs. But shouldn't my application run without macdeployqt
when I execute it directly with the Qt Creator?
I'm using MacOS X 10.14 with Qt 5.11.3. Xcode 10 and the MacOSX SDK 10.13 is installed and setted up correctly (at least it compiles with this SDK and without any error).
Does anyone has an idea?
Upvotes: 31
Views: 39287
Reputation: 85
I had the same issue. I was using MacOS Sonoma 14.5 and a M1 chip. I was using PyQt5 and pyproject to create a package of my project.
I tried setting QT_QPA_PLATFORM_PLUGIN_PATH
to several different values. I even set QT_DEBUG_PLUGINS=1
according to https://forum.qt.io/topic/133532/how-to-solve-could-not-load-the-qt-platform-plugin-cocoa-in-even-though-it-was-found.
None of these steps worked for for me.
What ended up working for me was to remove my .venv
folder and reinitializing the python environment to create a fresh venv. It appears something corrupted my PyQt in the environment.
Upvotes: 0
Reputation: 841
If you are on Mac, go to the Terminal and paste the following:
pip3 install opencv-python-headless
The Qt platform plugin requires this library to be installed.
Thanks!
Upvotes: 45
Reputation: 644
Try setting QT_QPA_PLATFORM_PLUGIN_PATH to the plugin directory of where you installed qt.
E.g. if QT is installed in /Users/ABC/qt, then export QT_QPA_PLATFORM_PLUGIN_PATH=/Users/ABC/qt/plugins likely fixes your problem (did it for me on my brew installed qt).
Upvotes: 15
Reputation: 1279
I've posted the same question a few days ago on the official Qt forum, because I haven't got a response here on Stackoverflow: https://forum.qt.io/topic/98816/qt-could-not-find-the-platform-plugin-cocoa
The problem seems to be that I've installed Qt on /Library/Qt (outside of the user directory). After reinstalling Qt to /Users/ABC/Qt and a complete rebuild of my project everything seems to work now.
Upvotes: 4