已解决 - 在Docker容器中使用PyQt5 GUI:
启用Qt-Debug $ export QT_DEBUG_PLUGINS=1
==> 重现错误 ==> 安装或重新安装调试消息中列出的No such file or directory
库 ==> 重复以上步骤!
我在Docker容器中无法运行PyQt5-GUI应用程序,首先阅读了所有关于无法在Docker容器中运行Qt的帖子。但是我找到了解决方法(至少对我有效)...
系统
我正在使用共享的/tmp/.X11-unix/
套接字和显示器来运行我的PyQt5应用程序在Docker容器中进行GUI可视化:
$ nividia-docker run --interactive --tty --env DISPLAY=$DISPLAY --volume /tmp/.X11-unix/:/tmp/.X11-unix/ <docker_iamge>
错误
初始化 PyQt5.QtWidgets.QApplication
始终导致以下错误:
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtWidgets import QApplication
>>> app = QApplication([])
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)
在PyCharm调试模式下,会返回错误信息:
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
解决方案
通用方法:
- 在 docker 容器终端中设置 Qt-debug 环境变量:
$ export QT_DEBUG_PLUGINS=1
$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
KeyboardInterrupt
>>> from PyQt5.QtWidgets import QApplication, QLabel
>>> app = QApplication([])
QFactoryLoader::QFactoryLoader() checking directory path "/conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/libqeglfs.so"
Found metadata in lib /conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/libqeglfs.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"eglfs"
]
},
...
...
...
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/conda/envs/rapids/bin/platforms" ...
Cannot load library /conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so" : "Cannot load library /conda/envs/rapids/lib/python3.6/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxkbcommon-x11.so.0: 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.
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)
请查找
<No such file or directory>.so.*
和
<coud not be loaded>
相关的软件包,例如
libxkbcommon-x11.so.0
和
libxcb
。然后重新安装相应的软件包/库(使用
apt-file --package-only search <filename>
或
conda/pip search ...
可找到软件包)。在我的情况下,需要以下库:
$ sudo conda install --name <env_name> --force-reinstall libxcb
$ apt-file --package-only search libxkbcommon-x11.so.0
libxkbcommon-x11-0
$ sudo apt install libxkbcommon-x11-0
在为所有顺序重现的调试消息重复此过程并安装了2个库之后,我现在可以从我的本地计算机桌面内部的Docker容器中运行PyQt5应用程序。