远程调试 qt.qpa.xcb: could not connect to display, echo DISPLAY为空[已解决]

  • 以服务器作为远程解释器,本地pycharmvscode调试时出现如下错误:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/xx/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

这和IDE不能直接回传图形界面相关,比如一份代码中添加cv.imshow()后报上述错误

  • 解决办法
    可借助第三方ssh软件
    windowspycharm为例,安装远程ssh软件MobaXterm(或其他支持图形回传的远程软件)
    输入下面命令
echo $DISPLAY
得到服务器的显示端口:

在这里插入图片描述
NOET
如果echo DISPLAY返回空,可以在mobaxterm启用终端处找到非本地DISPLAY端口
远程调试 qt.qpa.xcb: could not connect to display, echo DISPLAY为空[已解决]_第1张图片
vi /etc/profile内添加export DISPLAY=10.110.3.26:0.0
执行source /etc/profile
然后ssh终端安装xorg并使用xclock测试能否回传图像:

apt-get install xorg
xclock

点击PyCharm菜单栏pycharm-Run-Edit Configurations, 在Environment variable添加DISPLAY=localhost:10.0DISPLAY=10.110.3.26:0.0

远程调试 qt.qpa.xcb: could not connect to display, echo DISPLAY为空[已解决]_第2张图片

保证ssh软件和pycharm同时开启,重新运行程序,即可显示远端图像。

你可能感兴趣的:(错误与异常处理,服务器,ssh,opencv)