【已解决】GLFW error #65544: X11: Failed to open display :0 连接远程服务器并开启gui界面失败

本地计算机通过ssh连接服务器运行gui界面的时候报错,但是直接在服务器上跑gui代码没有任何问题。

Glfw Error 65544: X11: Failed to open display :0.0
Glfw Error 65537: The GLFW library is not initialized
Glfw Error 65537: The GLFW library is not initialized
Glfw Error 65537: The GLFW library is not initialized
Glfw Error 65537: The GLFW library is not initialized
python3: /home/runner/work/DearPyGui/DearPyGui/thirdparty/glfw/src/window.c:533: glfwSetWindowPos: Assertion `window != NULL' failed.

原因其实在于你本地没有设置显示gui的显示屏,如果之前一直ssh开gui没问题,用的好好地,突然不行了直接跳到第二步,否则从第一步开始看。

Step1. 服务器端ssh设置

sudo vim /etc/ssh/sshd_config
#查找X11Forwarding  如果是no 改成yes
X11Forwarding yes
#保存退出

修改完后执行命令 重启ssh服务

sudo systemctl restart sshd.service

然后即可通过vscode连接远程服务器了,可以输入以下命令测试

gedit a.txt

如果还是不行就看第二步

Step2. 修改display

客户端ssh bash输入以下命令

echo $DISPLAY  #可能会显示
:0.0

可以直接输入命令

export DISPLAY=:0

如果不行就输入

export DISPLAY=:1

到这里基本就解决问题了

这两条命令的作用是告诉ssh的bash 从哪个显示器显示gui界面。
如果有条件可以直接在服务器上操作,在服务器bash上执行以下命令

echo $DISPLAY  
:0 或者 :1

根据显示的内容x在远程ssh的bash里设置就没问题了
export DISPLAY=:x

猜你喜欢

转载自blog.csdn.net/Fucking_Code0916/article/details/129335057