python - 此应用程序无法启动,因为它无法在 "xcb"中找到或加载 Qt 平台插件 ""

标签 python qt anaconda pyqt5 miniconda

我有一个使用 Qt5 运行的应用程序(通过 PyQt)。我正在使用 miniconda 并且 python 代码已被 cythonized。该代码是在我的本地计算机上设置的,从原始 .py 文件生成的 cython 代码以及安装在 miniconda 中的相关库和模块,以便代码成功运行。然后我将所有内容发送到另一台机器,编译 cython 代码以提供 .so 文件并尝试运行它。此时我收到错误:

This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Reinstalling the application may fix this problem.
Aborted (core dumped)

我花了很长时间寻找可能的解决方案,并且获得了以下额外信息:

我已经检查了各种 .so 文件上的 ldd。似乎都找到了所需的库。

我尝试定位 libqxcb.so 并返回: ~/miniconda3/pkgs/qt-5.6.2-3/plugins/platforms/libqxcb.so & ~/miniconda3/plugins/platforms/libqxcb.so

基于建议here从 TranslucentCloud,我已将其复制到目录 ~/miniconda3/bin/platforms (新创建的)。

我还在调用我的代码的脚本中包含了 export QT_DEBUG_PLUGINS=1 。这给出了以下输出:

QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "~/miniconda3/bin/platforms/libqxcb.so"
Found metadata in lib ~/miniconda3/bin/platforms/libqxcb.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
    "MetaData": {
        "Keys": [
            "xcb"
        ]
    },
    "className": "QXcbIntegrationPlugin",
    "debug": false,
    "version": 329218
}


Got keys from plugin meta data ("xcb")
loaded library "~/miniconda3/bin/platforms/libqxcb.so"
xkbcommon: ERROR: failed to add default include path ~/Programmes/miniconda3/lib
Qt: Failed to create XKB context!
Use QT_XKB_CONFIG_ROOT environmental variable to provide an additional search path, add ':' as separator to provide several search paths and/or make sure that XKB configuration data directory contains recent enough contents, to update please see http://cgit.freedesktop.org/xkeyboard-config/ .
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/xcbglintegrations" ...
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/platformthemes" ...
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/platforminputcontexts" ...
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/styles" ...
Fontconfig error: Cannot load default config file
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/accessible" ...
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/accessiblebridge" ...
QXcbConnection: XCB error: 145 (Unknown), sequence: 165, resource id: 0, major code: 139 (Unknown), minor code: 20
QFactoryLoader::QFactoryLoader() checking directory path "~/miniconda3/bin/imageformats" ...
QLibraryPrivate::unload succeeded on "~/miniconda3/bin/platforms/libqxcb.so"

GUI 现在加载并且按钮等可以工作。但是,仍然存在一些问题 - 小问题是所有字体都与我的本地计算机不同(不是主要问题,但可能表明它仍然没有找到一些相关的库)。

更严重的是,GUI 不会响应任何按键 - GUI 有很多文本框需要填写,因此这使其无法使用。

上面的输出中显然仍然存在一些错误,但是,从中不清楚哪些库等仍然无法找到(或者为什么会出现这种情况)。

最佳答案

需要采取一些步骤来解决上述错误:

This application failed to start because it could not find or load the Qt platform plugin "xcb"
in "".

Reinstalling the application may fix this problem.
Aborted (core dumped)

可以通过将 ~/miniconda3/plugins/platforms 复制到 ~/miniconda3/bin 来解决此问题。

此外,在启动 Qt GUI 的 bash 脚本中,我添加了以下几行,否则 GUI 中的所有文本都会出现在 Courier 中:

export FONTCONFIG_FILE=/etc/fonts/fonts.conf
export FONTCONFIG_PATH=/etc/fonts/

最后,我还需要以下行来允许 GUI 注册按键:

export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb

解决这个问题的关键是这一行: export QT_DEBUG_PLUGINS=1 这使我能够看到 Qt 的问题所在。

关于python - 此应用程序无法启动,因为它无法在 "xcb"中找到或加载 Qt 平台插件 "",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42595685/

相关文章:

c++ - QGLWidget 中的 makeCurrent() 在哪里使用?

python - 无法使用 Jupyter Notebook : jsonschema apparently missing

python - 在我的 Qt C++ 应用程序中使用 Anaconda 的 Python

python - 在 miniconda 中使用 environment.yml 创建虚拟环境

javascript - 使用 selenium 和 python 在网页中打印 javascript 的输出

python - XGboost - 增加训练错误 "mae"

python - 使用 ec2 创建存储在 s3 上的图像缩略图并在完成时与 rails 通信的优雅方式?

python - 将文件转换为列表的最快方法?

c++ - 在单独的线程中使用 QTimer 的规范方式

python - 使用自定义模型编辑 QTreeView 中的第二列不显示编辑器