2

I am working with visual studio code (python) using ssh to access a remote server (where the code is located). I am able to write code, run and debug without any problem. However I am not able to generate matplotlib figures during debug in the same way as i can do it without the ssh connection.

I've tried to follow several suggestions from internet and other post here but none of them is fully working.

  • I've tried the option of " Jupiter> Debug current file in interactive window " but it does not work. I am not sure why, but the debug in the interactive window is not responding and i can not work during debug.

  • I've tried python debug and the only matplotlib backend that works is (matplotlib.use("WebAgg"). However for this backend it only works with one figure and the debug is block after the plot.

  • I have also tried to use X.Org (in my case xquartz over mac) but the figures are really slow and it is not useful.

Any idea on how to plot figures during debug in the same way as in local development?

Thanks!

VictorCB
  • 70
  • 10
  • 1
    `I've tried the option of " Jupiter> Debug current file in interactive window " but it does not work. I am not sure why, but the debug in the interactive window is not responding and i can not work during debug.` This will not work because Jupyter will wait for the current cell to finish before you can run the next cell. If you have a breakpoint somewhere, it will be waiting until you continue. [More info here](https://github.com/microsoft/vscode-jupyter/issues/1278#issuecomment-1167574874). The solution is to use the Python Debug Console for interacting with your code at your breakpoint. – fabda01 Jul 14 '22 at 01:50
  • Thanks. I've tried and it works. However, i am not able to pop-up the figures from the interactive window. Is there a way to do that (taking into account that i am with a n ssh connection) ? – VictorCB Jul 14 '22 at 15:20
  • The idea is to use Jupyter notebooks to render your plots in a ssh connection. I don't see why, but if you want to pop-up a matplotlib window through ssh, you will need to expose your display server with your remote session. I think there is already a question about that on StackOverflow: [Open a Matplotlib figure through SSH tunnel of vscode](https://stackoverflow.com/questions/57152770/open-a-matplotlib-figure-through-ssh-tunnel-of-vscode). But again, why would you want to render plots on a separate window if you already can easily do it via Jupyter notebooks? – fabda01 Jul 15 '22 at 03:10
  • As I am used to work with pop up windows, for my work is quite convenient to have different windows with images (like imshow). My idea is that then with the mouse you can easily make zoom and see the value of each pixel quite fast. I know that i can use libraries like mpl-interactions but (correct me if i am wrong) as far as i know i can not "play" with matplotlib in the interactive window. – VictorCB Jul 15 '22 at 10:07

1 Answers1

2

I asked this question in GitHub and got the following answers:

One way to do this is to do the 'Debug your current file in the interactive window'.

There's a bunch of caveats though.

  1. You need to have ipykernel installed into the python environment you're using. If you run that command it should have asked you to do so.
  2. It's likely easier to use if you put cell markers around pieces of code # %%. This would also allow you to prerun bits of your script before you need to debug the part that's causing problems. This is what it looks like when you do that:

enter image description here

  1. When debugging in the interactive window, your code in your script is running as an IPython cell. If you split it up, it might be multiple cells or it could be one large cell (for the whole file).
  2. As you step, the cell execution is moved forward one line at a time. However the execution is paused in between steps. This means anything you type in the interactive window won't be executed. Instead you have to run extra code in the 'debugger console'. Shown below:

enter image description here

  1. This debugger console is where you can run normal matplotlib commands.
MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13