因此,我有一个相当大的python程序,我想将它移植到其他机器(ubuntu 18.04),而不必为每台机器安装所有python包和依赖项,为此我选择使用cx_Freeze
,似乎可以将项目很好地构建到单个可执行文件中,但调用cv2.imshow
时可执行文件崩溃。我设法用这段代码重现了错误:
import numpy as np
import cv2
img = cv2.imread('monke.jpg',0)
cv2.imshow("img", img)
这是我的cx_Freeze
构建脚本:
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": []}
# GUI applications require a different base on Windows (the default is for
# a console application).
setup(
name = "test",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("cv2_test.py")]
)
这就是我得到的错误:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins" 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: xcb.
Aborted (core dumped)
我还尝试使用QT_DEBUG_PLUGINS=1
运行程序以获得更详细的错误输出:
QFactoryLoader::QFactoryLoader() checking directory path "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins" ...
QFactoryLoader::QFactoryLoader() checking directory path "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7" ...
QFactoryLoader::QFactoryLoader() looking at "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/cv2_test"
"Failed to extract plugin meta data from '/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/cv2_test'"
not a plugin
QFactoryLoader::QFactoryLoader() looking at "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/monke.jpg"
QElfParser: '/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/monke.jpg' is not an ELF object
"'/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/monke.jpg' is not an ELF object"
not a plugin
QFactoryLoader::QFactoryLoader() checking directory path "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms" ...
QFactoryLoader::QFactoryLoader() looking at "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms/libqxcb.so"
Found metadata in lib /home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms/libqxcb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"xcb"
]
},
"archreq": 0,
"className": "QXcbIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/platforms" ...
Cannot load library /home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms/libqxcb.so: (libQt5XcbQpa-70670cdb.so.5.15.0: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms/libqxcb.so" : "Cannot load library /home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins/platforms/libqxcb.so: (libQt5XcbQpa-70670cdb.so.5.15.0: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/vaki/Desktop/cv2_test/build/exe.linux-x86_64-3.7/lib/cv2/qt/plugins" 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: xcb.
如有任何帮助/建议,将不胜感激。我尝试使用pyInstaller,但它甚至无法构建项目
因此,多亏了另一个答案中的jpeg,我通过将以下代码片段添加到我的构建脚本中,成功地解决了这个问题:
问题可能是
cv2/qt/plugins
没有完全包含在cx\u Freeze中尝试按如下方式修改生成脚本的开头:
(未测试,可能需要微调)
这应该告诉cx_Freeze将包含到整个文件夹
cv2/qt/plugins
的正确位置,请参阅cx_Freezedocumentation相关问题 更多 >
编程相关推荐