语言:python==3.8.5
平台:Anaconda==4.9.2
操作系统:Ubuntu 20.10
包:opencv-contrib-python==4.5.1.48
IDE:VS Code 2020
执行时出现此错误cv2.imshow('Final', src_img)
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/ubuntu/anaconda3/lib/python3.8/site-packages/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, eglfs, minimal, minimalegl, offscreen, vnc.
Aborted (core dumped)
执行与QT_DEBUG_PLUGIN=1 script.py
QFactoryLoader::QFactoryLoader() looking at "/home/bas/anaconda3/plugins/platforms/libqxcb.so"
Found metadata in lib /home/bas/anaconda3/plugins/platforms/libqxcb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"xcb"
]
},
"className": "QXcbIntegrationPlugin",
"debug": false,
"version": 329991
}
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/home/bas/anaconda3/bin/platforms" ...
loaded library "/home/bas/anaconda3/lib/python3.8/site-packages/cv2/qt/plugins/platforms/libqxcb.so"
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/bas/anaconda3/lib/python3.8/site-packages/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, eglfs, minimal, minimalegl, offscreen, vnc.
Aborted (core dumped)
仅当我在 vs code 终端中运行脚本时才会出现此问题。该脚本在 ubuntu-terminal 中执行时运行没有错误。
对此问题的一些帮助将不胜感激。谢谢