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

问题:以服务器作为远程解释器,本地pycharm或vscode调试时出现如下错误:

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

出现这种问题并不是Qt安装有问题也不是pycharm配置有问题,而是qt找不到图形输出端口,这和IDE不能直接回传图形界面相关,比如一份代码中添加cv.imshow()后报上述错误。

解决办法
借助远程ssh连接工具
以windows和pycharm为例,安装远程ssh软件MobaXterm(或其他支持图形回传的远程软件)
输入

echo $DISPLAY

得到服务器的显示端口:
在这里插入图片描述

如果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.0 DISPLAY=10.110.3.26:0.0
远程调试 qt.qpa.xcb: could not connect to display, echo DISPLAY为空[已解决]_第2张图片

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

原文地址:
https://blog.csdn.net/qq_34907927/article/details/116597908

你可能感兴趣的:(Linux,python)