pyqt5报错qt.qpa.plugin: Could not load the Qt platform plugin “windows“ in ““ even though it was found

win10 64位系统,安装anaconda3,python 版本3.7.4,刚开始安装了pyqt5,pyqt5-tools ,然后好用,可以使用图形界面,然后又安装了其它包或软件,就报错了,出不来图形界面。调用方式使用命令行,python test2.py,其中test2.py包含qt的图形界面程序

报错如下

qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: minimal, offscreen, webgl, windows.

尝试了如下方法:

(1)pip卸载重新安装pyqt5,pyqt5-tools,

(2)将dll 文件或dll文件所在的文件夹移动到Anaconda3\Library\plugins\platforms,

(3)conda 新建虚拟环境,并安装pyqt5,pyqt5-tools,

(4)修改环境变量法,即删除QT_PLUGIN_PATH,并删除PATH里包含platforms文件夹的项,其中platforms 文件夹中包含qwindows.dll

试过以上方法,发现报错一样,论坛上说版本不对,调试了一下

SET QT_DEBUG_PLUGINS=1

python test2.py
QFactoryLoader::QFactoryLoader() checking directory path "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qminimal.dll"
Found metadata in lib D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qminimal.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "minimal"
        ]
    },
    "archreq": 0,
    "className": "QMinimalIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("minimal")
QFactoryLoader::QFactoryLoader() looking at "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qoffscreen.dll"
Found metadata in lib D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qoffscreen.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "offscreen"
        ]
    },
    "archreq": 0,
    "className": "QOffscreenIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("offscreen")
QFactoryLoader::QFactoryLoader() looking at "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qwebgl.dll"
Found metadata in lib D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qwebgl.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "webgl"
        ]
    },
    "archreq": 0,
    "className": "QWebGLIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("webgl")
QFactoryLoader::QFactoryLoader() looking at "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qwindows.dll"
Found metadata in lib D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qwindows.dll, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "windows"
        ]
    },
    "archreq": 0,
    "className": "QWindowsIntegrationPlugin",
    "debug": false,
    "version": 331520
}


Got keys from plugin meta data ("windows")
QFactoryLoader::QFactoryLoader() checking directory path "D:/Anaconda3/platforms" ...
Cannot load library D:\Anaconda3\Lib\site-packages\PyQt5\Qt5\plugins\platforms\qwindows.dll: 找不到指定的程序。
QLibraryPrivate::loadPlugin failed on "D:/Anaconda3/Lib/site-packages/PyQt5/Qt5/plugins/platforms/qwindows.dll" : "Cannot load library D:\\Anaconda3\\Lib\\site-packages\\PyQt5\\Qt5\\plugins\\platforms\\qwindows.dll: 找不到指定的程序。"
qt.qpa.plugin: Could not load the Qt platform plugin "windows" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: minimal, offscreen, webgl, windows.

conda list 查看pyqt 的版本

pyqt                      5.9.2            py37hd77b12b_6    defaults
pyqt5                     5.15.9                   pypi_0    pypi
pyqt5-plugins             5.15.9.2.3               pypi_0    pypi
pyqt5-qt5                 5.15.2                   pypi_0    pypi
pyqt5-sip                 12.12.2                  pypi_0    pypi
pyqt5-tools               5.15.9.3.3               pypi_0    pypi
pyqtwebengine             5.15.6                   pypi_0    pypi
pyqtwebengine-qt5         5.15.2                   pypi_0    pypi

我无法确认是否版本不对,也有可能是,最后又新安装了python38,然后安装pyqt5,pyqt5-tools解决的,水平有限,欢迎批评指正

参考资料:

Could not load the Qt platform plugin "windows" in "" even though it was found. | Qt Forum

2

"could not find or load the Qt platform plugin "windows" in "", | Qt Forum

3【已解决】qt.qpa.plugin: Could not load the Qt platform plugin “windows“ in ““ even though it was found.-优快云博客

Could not load the Qt platform plugin “windows“ in ““ even though it was found._could not load the qt platform plugin "windows" in_小龙狗的博客-优快云博客

5

PyQt5解决Qt platform plugin could be initialized - 知乎

<think>好的,我现在需要解决用户遇到的Qt平台插件'xcb'加载失败的问题。用户提到错误信息是“qt.qpa.plugin: Could not load the Qt platform plugin ‘xcb’”,并且引用了四个相关的参考资料。我需要仔细分析这些引用,找出解决方案,并按照用户的要求用中文回答,结构清晰,分步骤说明。 首先,我要回顾用户提供的引用内容。引用[1]、[2]、[3]和[4]都涉及类似的问题,即Qt应用程序无法加载xcb插件。根据引用[4],问题通常是由于缺少依赖库导致的,可以通过设置QT_DEBUG_PLUGINS=1来查看详细的错误信息,定位缺失的库。在Ubuntu系统中,可能需要安装libxcb-xinerama0,而在CentOS中可能是libxkbcommon-x11-devel。此外,引用[2]和[3]提到即使插件路径正确,仍可能加载失败,可能需要设置环境变量如QT_QPA_PLATFORM_PLUGIN_PATHQT_PLUGIN_PATH指向正确的插件目录。还有可能需要设置DISPLAY环境变量,确保X服务器运行,尤其是在无头环境中可能需要使用虚拟显示如Xvfb。 接下来,我需要整理出解决步骤。首先检查依赖库是否安装,然后检查环境变量是否正确设置,包括插件路径和DISPLAY变量。如果问题仍然存在,可能需要重新安装相关软件包或使用虚拟显示。同时,用户可能需要根据不同的系统(Ubuntu或CentOS)安装不同的库,如引用[4]所述。 需要注意的是,用户可能在命令行或远程SSH会话中运行程序,这时候DISPLAY变量可能未设置,导致X11连接失败。这种情况下,安装xcb相关库或配置虚拟显示可能会有帮助。此外,确保Qt插件路径正确,避免路径中有中文或特殊字符,这可能会影响插件的加载。 最后,生成相关问题,这些问题应该围绕Qt插件加载失败的其他可能原因、不同系统的依赖安装、环境变量的设置方法,以及虚拟显示的使用场景展开。</think>### 逐步解决方案:Qt平台插件'xcb'加载失败问题 #### 1. **检查缺失的依赖库** - **定位缺失库**:在终端执行以下命令启用调试模式,查看具体缺失的库: ```bash export QT_DEBUG_PLUGINS=1 your_qt_application # 替换为实际程序名(如python脚本或编译后的程序) ``` 根据输出提示的缺失文件名(如`libxcb-xinerama.so.0`),安装对应库: - **Ubuntu/Debian**: ```bash sudo apt install libxcb-xinerama0 libxkbcommon-x11-0 ``` - **CentOS/RHEL**: ```bash sudo yum install libxkbcommon-x11-devel libxcb-util ``` - 若无法确定包名,可通过网站(如[rpmfind.net](http://rpmfind.net))搜索文件名对应的安装包[^4]。 #### 2. **设置环境变量** - **指定插件路径**:若插件路径未被正确识别,手动设置`QT_PLUGIN_PATH`: ```bash export QT_PLUGIN_PATH=/path/to/qt/plugins # 例如:$HOME/anaconda3/envs/your_env/lib/python3.7/site-packages/cv2/qt/plugins ``` - **强制使用xcb插件**: ```bash export QT_QPA_PLATFORM=xcb ``` #### 3. **检查X11显示配置** - **验证DISPLAY变量**:确保当前会话已设置有效的显示接口: ```bash echo $DISPLAY # 正常应返回类似":0"或":1" ``` 若未设置(如通过SSH连接),需启用X11转发: ```bash ssh -X user@host # 使用-X选项连接 ``` - **使用虚拟显示(无GUI环境)**:安装`Xvfb`并启动虚拟显示: ```bash sudo apt install xvfb # Ubuntu Xvfb :99 -screen 0 1024x768x24 & export DISPLAY=:99 ``` #### 4. **重新安装相关软件包** - 若依赖库和环境变量均正确,但问题仍存在,尝试重新安装: ```bash # 对于OpenCV-Python或PyQt pip uninstall opencv-python-headless pyqt5 pip install opencv-python-headless pyqt5 --force-reinstall ``` #### 5. **验证Qt插件路径** - 检查程序是否从正确路径加载插件: ```bash strace -e openat your_qt_application 2>&1 | grep "xcb" ``` 确保输出中显示的路径包含`platforms/libqxcb.so`。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值