基于pyqt5开发了GUI程序,想要在x86架构下的CentOS7系统下使用pyinstaller打包成可执行程序并运行,打包比较顺利,但运行时报错了,这里记录下问题解决过程。
报错信息如下:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" 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: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
Aborted (core dumped)
解决步骤
- 设置环境变量QT_DEBUG_PLUGINS
export QT_DEBUG_PLUGINS=1
- 再次运行程序查看最下方的报错信息,会显示缺少的库
...
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/opt/tdtool/platforms" ...
Cannot load library /tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so" : "Cannot load library /tmp/_MEIhUBkwl/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
...
- 去这个网站http://rpm.pbone.net/搜索库对应的包名
- 使用yum安装缺少的包,我的环境缺少如下包
yum install libxcb libxcb-devel libXrender libXrender-devel xcb-util-wm xcb-util-wm-devel xcb-util-image xcb-util-image-devel xcb-util-keysyms xcb-util-keysyms-devel xcb-util-renderutil xcb-util-renderutil-devel libxkbcommon-x11 libxkbcommon-x11-devel
- 再次运行程序,成功
通过MobaXterm运行GUI程序
MobaXterm通过SSH连接服务器后,需要启动X Server并设置环境变量DISPLAY后才可以
-
启动X Server
-
设置DISPLAY环境变量
export DISPLAY=172.xx.xx.xx:0.0 # 变量值是下图中绿色框中的内容
如果DISPLAY如下图所示自动设置了,则不需要设置,此时使用echo $DISPLAY是能够看到结果的
界面中文显示为小方框问题
界面上的中文显示为小方框是系统缺少字体导致,解决办法:
- 在 /usr/share/fonts路径下新建windows目录
- 将 C:\Windows 目录下的Fonts整个文件夹拷贝到linux系统的 /usr/share/fonts/windows 路径下,即 /usr/share/fonts/windows/Fonts路径下是字体文件
- 重新运行GUI程序,界面上中文显示正常