当前位置: 首页 > article >正文

pyqt5报错:qt.qpa.plugin: Could not find the Qt platform plugin “xcb“(已解决)

我在使用pyqt库的时候报错:

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in \
"/mnt/private_disk/anaconda3/envs/aot-manip/lib/python3.8/site-packages/PyQt5/Qt5/plugins/platforms" 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.

启动调试模式:export QT_DEBUG_PLUGINS=1,我发现这么一段报错:

QFactoryLoader::QFactoryLoader() checking directory path \
"/mnt/private_disk/anaconda3/envs/aot-manip/bin/platforms" ...
Cannot load library .../libqxcb.so: (/lib/x86_64-linux-gnu/libQt5XcbQpa.so.5: undefined symbol: \
_ZN23QPlatformVulkanInstance22presentAboutToBeQueuedEP7QWindow, version Qt_5_PRIVATE_API)

这个undefined symbol的问题我之前也遇到过!

经过多番询问AI,发现了问题的缘由:

根据你的调试输出,核心问题在于 libQt5XcbQpa.so.5 中存在未定义的符号
_ZN23QPlatformVulkanInstance22presentAboutToBeQueuedEP7QWindow,这表明 ​Qt 库版本存在不兼容或依赖链断裂。

于是通过 ldd /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/libqxcb.so 查看依赖的 Qt 库路径。我发现依赖的路径鱼龙混杂,有和anaconda相关的,有和coppeliaSim相关的,有在/usr/lib路径下的。

这和我之前使用CoppeliaSim时配置环境的遗留问题相关,执行vim ~/.bashrc,发现了之前的配置

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COPPELIASIM_ROOT
export QT_QPA_PLATFORM_PLUGIN_PATH=$COPPELIASIM_ROOT
export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu/:$LD_LIBRARY_PATH

解决方案比较简单,我首先注释掉了上面三行,不让pyqt去找系统目录下的LD_LIBRARY_PATHQT_QPA_PLATFORM_PLUGIN_PATH
然后在python代码中设置QT_QPA_PLATFORM_PLUGIN_PATH:

os.environ.update({"QT_QPA_PLATFORM_PLUGIN_PATH": \
"/mnt/private_disk/anaconda3/envs/aot-manip/lib/python3.8/site-packages/PyQt5/Qt5/plugins/platforms"})

网上还有一种配置方法export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins/platforms,据我猜测,这是使用c++开发Qt的配置方案,而我们用pip安装好的pyqt是自给自足的,不需要suda apt install Qt相关的库。


http://www.kler.cn/a/595045.html

相关文章:

  • 绕过 reCAPTCHA V2/V3:Python、Selenium 指南
  • AD(Altium Designer)已有封装库的基础上添加器件封装
  • 考研c语言复习之栈
  • 深度学习:从零开始的DeepSeek-R1-Distill有监督微调训练实战(SFT)
  • Python 元组(tuple)大全
  • PostgreSQL_数据回退,数据库导出、导入
  • 洛谷 P2157 [SDOI2009] 学校食堂
  • 清华最新出品YOLOE: 开放检测与分割模型、支持多提示机制与零样本迁移【附源码与论文】
  • ClickHouse 深度解析:列式存储为何成为 OLAP 的「核武器」
  • 【Java基础】在Java中,一个线程的大小(即线程所占用的内存)是多少
  • 嵌入式Linux——Framebuffer应用编程
  • 算法系列——有监督学习——4.支持向量机
  • 【Pandas】pandas Series plot.barh
  • 区块链交易所平台开发全解析
  • Microsoft Edge浏览器的取证分析(基于Chromium)
  • GitHub在push推送到远程仓库的时候显示Logon failed登录失败
  • Powershell美术资产批量重命名
  • 使用系统Picker
  • Performance Hub Active Report
  • Deepseek X 文心智能体:提示词工程猫