qt.qpa.plugin:在“”中找不到Qt平台插件“cocoa”

问题描述 投票:0回答:1

我正在使用 PyQt6 编写一个应用程序,但是当打开一个简单的主窗口时,我收到以下错误:

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

我尝试在网络上运行建议的解决方案(重新安装 Qt 并安装 opencv-python-headless),但没有成功。你能帮我弄清楚发生了什么事吗?

谢谢!

斯特凡诺

macOS 文图拉 13.4.1 蟒蛇3.11.3

python-3.x qt cocoa plugins pyqt6
1个回答
0
投票

我首先解决了寻找文件 libqcocoa.dylib 并找到其完整路径(在我的情况下

/Users/<user>/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins/platforms
,但这取决于您使用的内容:PyQt5、PyQt6 或简单的 Qt)。

然后我更新了变量 QT_PLUGIN_PATH:

export QT_PLUGIN_PATH=/Users/xizg0003/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins

为了使更改永久化,我找到了文件 qt.conf(在我的例子中位于

/Users/<user>/anaconda3/bin
)并将插件目录路径添加到该文件,就在 [Paths] 下方:

Plugins = /Users/<user>/anaconda3/lib/python3.11/site-packages/PyQt6/Qt6/plugins

© www.soinside.com 2019 - 2024. All rights reserved.