pycharm远程调试:_tkinter.TclError: couldn't connect to display "localhost:10.0"

PyCharm远程开发配置

pycharm远程配置具体请参考:https://blog.csdn.net/qq_38410428/article/details/82945084

背景

远程服务器上OS版本为Ubuntu16.04。准备用Win10进行远程开发,按照上述教程配置完PyCharm后,可以正常调用远程python解释器,但是当我程序产生窗口或者图片时,发现本地机器无法显示加载出来窗口或者图片。于是上网搜了很多资料,最终解决了这个问题。
pycharm远程调试:_tkinter.TclError: couldn't connect to display

解决方案

Win10需要安装的软件

  • PuTTy
  • Xming

软件配置

PuTTy

  • 打开PuTTy,点击Session,输入远程服务器IP,端口地址(默认22)
    pycharm远程调试:_tkinter.TclError: couldn't connect to display

  • 点击Connection->Data,设置Auto-login username(这样每次登录PuTTy就不需要设置远程服务器用户名了),Auto-login username是远程服务器的登录用户名
    pycharm远程调试:_tkinter.TclError: couldn't connect to display

  • 打开Connection->SSH->X11,设置X11 forwarding:(因为Xming图中标示出的“Display number”中的数字默认为0,所以X display location 填写localhost:0
    pycharm远程调试:_tkinter.TclError: couldn't connect to display

Xming

  • 对于简单的使用来说,不需要任何特殊的配置,一切使用默认即可。第一次运行时使用开始菜单里面的XLaunch来启动,产生一个初始的配置文件。可以将此初始配置文件保存起来,这样就不需要每次都重新配置了。

pycharm远程调试:_tkinter.TclError: couldn't connect to display

PyCharm

  • 打开Pycharm,选择run->edit configurations->在environment variables中添加DISPLAY=localhost:10.0
  • DISPLAY=localhost:10.0 根据如下命令查看:
    打开PuTTy,输入echo $DISPLAY ,输出结果为localhost:10.0,所以添加DISPLAY=localhost:10.0
    pycharm远程调试:_tkinter.TclError: couldn't connect to display

pycharm远程调试:_tkinter.TclError: couldn't connect to display

重新调用远程服务器运行程序,运行成功

pycharm远程调试:_tkinter.TclError: couldn't connect to display

注意

PuTTy,Xming,pycharm三个软件要同时运行。

你可能感兴趣的:(python)