之前用的PyQt5,现在安装完PyQt6,运行程序时报错:

qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqminimalegl.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqwebgl.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqminimal.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqoffscreen.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqxcb.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqvnc.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforms/libqeglfs.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platformthemes/libqxdgdesktopportal.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforminputcontexts/libqtvirtualkeyboardplugin.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforminputcontexts/libibusplatforminputcontextplugin.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/platforminputcontexts/libcomposeplatforminputcontextplugin.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/xcbglintegrations/libqxcb-egl-integration.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/xcbglintegrations/libqxcb-glx-integration.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
QXcbIntegration: Cannot create platform OpenGL context, neither GLX nor EGL are enabled
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/iconengines/libqsvgicon.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqico.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqwbmp.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqicns.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqjpeg.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqtga.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqtiff.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqsvg.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqpdf.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqgif.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/imageformats/libqwebp.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/designer/libqquickwidget.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
qt.core.plugin.loader: In /mnt/nas/pangshumao/software/anaconda3/plugins/designer/libqwebengineview.so:
  Plugin uses incompatible Qt library (5.15.0) [release]
QOpenGLWidget is not supported on this platform.

查了很多资料,都没找到解决方案,所以记录一下。

解决办法:

1. 在程序开头加入如下代码,开启QT调试模式:

os.environ['QT_DEBUG_PLUGINS'] = '1'

2. 再次运行程序,定位错误原因:

qt.core.plugin.factoryloader: Got keys from plugin meta data QList("webp")
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/bin/imageformats" ...
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqtiff.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqicns.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqtga.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqjpeg.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqsvg.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqwbmp.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqico.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqpdf.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqgif.so" loaded library
qt.core.library: "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/imageformats/libqwebp.so" loaded library
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/plugins/accessible" ...
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/accessible" ...
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/bin/accessible" ...
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/plugins/accessiblebridge" ...
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins/accessiblebridge" ...
qt.core.plugin.factoryloader: checking directory path "/mnt/nas/pangshumao/software/anaconda3/bin/accessiblebridge" ...

3. 出错的原因分析:大概是因为qt插件环境变量QT_PLUGIN_PATH的问题,当前的QT_PLUGIN_PATH是"/mnt/nas/pangshumao/software/anaconda3/plugins",该目录下的很多库文件是qt5的,不适用于qt6。

解决办法:更改QT_PLUGIN_PATH为"/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins"。(注意:第一步的代码要去掉。)

程序开头加入下面这行:

os.environ['QT_PLUGIN_PATH'] = '/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins'

或者在终端运行如下命令:

export QT_PLUGIN_PATH=/mnt/nas/pangshumao/software/anaconda3/lib/python3.9/site-packages/PyQt6/Qt6/plugins

搞定。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐