4

I am using vscode remote ssh and connect to my server (a node in a cluster) via ssh. My local machine is Windows and my Host is ubuntu. My vscode is being used to code in python.

I am trying for weeks to be able to run a python code and display images in the debug console like what we do in the normal terminal or in jupyter notebook, but I notice that I cannot display the image in the debug console at all. here is a toy example

import numpy as np
import matplotlib.pyplot as plt
img =  np.random.rand(300,200)
plt.imshow(img);plt.show()

basically when I try to do plt.imshow(img);plt.show() in the debug console I either get nothing or I get qt.qpa.screen: QXcbConnection: Could not connect to display localhost:0.0 Could not connect to any X display. . I tried several methods such as using x11 extenson or adding x11 forwarding in the putty or add Display in the launch.json. However, none of them works.

I am coming to the conclusion that vscode remote ssh and debug console in python dont have that feature yet. But if you know a way to do it PLEASE let me know.

I hope that I am clear that displaying image in the normal situation is working and it is not working in the debug situation. Please note that when I am doing the debug I dont want to display the image out side of the debug console.

Thanks

sey eeet
  • 229
  • 2
  • 8

1 Answers1

2

it seems you have done the first steps of my proposed solution.

  1. open your settings in vscode with ctrl+, and search for terminal.integrated.env.linux. Click Edid settings.json
  2. Update terminal.integrated.env.linux to this
"terminal.integrated.env.linux": {
    "DISPLAY": "localhost:10.0",
  }
  1. Shut down vscode
  2. Open ssh conncetion to server with ssh -X user@host
  3. Open vscode and use remote development add-on as usually.

Now, this will work indefinitely, just open the x11-forwarding on the side every time. The downside, for which I am currently searching for solution is that you need to remove the "DISPLAY": "localhost:10.0" every time you wish to develop locally, which is not optimal.

Edit: Since you are apparently using windows, you need to configure putty with X11 forwarding and use xming or other x11-forwarding software in place of my step 4.