Home > database >  VS Code integrated terminal doesn't launch GUI applications
VS Code integrated terminal doesn't launch GUI applications

Time:02-18

While I'm able to run scripts from Ubuntu terminal, the integrated terminal on VS Code doesn't run correctly when it comes to launching GUI applications. Consider these examples:

PIL Example

from PIL import Image
img = Image.open('image.png')
img.show()
  • Behavior on System Terminal: Launches default image viewer
  • Behavior on VS Code Integrated Terminal: A warning is printed (Gtk-WARNING cannot open display)

Browser / Plotly Example

import plotly.graph_objects as go
fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"
)
fig.show()
  • Behavior on System Terminal: Launches default web browser
  • Behavior on VS Code Integrated Terminal: Nothing

Text Editor Example

git rebase -i origin/main
  • Behavior on System Terminal: Launches default text editor
  • Behavior on VS Code Integrated Terminal: Nothing

I have reported this bug here but I'm think it may not be a bug.

CodePudding user response:

Probably the DISPLAY variable is not set in your VS code shell. Find out the value in your working system terminal:

echo $DISPLAY

Then set the value in VS Code via the terminal.integrated.env.<platform> setting. Press Ctrl Shift P and search for Preferences: Open Settings (JSON). Add the following entry to the settings file:

"terminal.integrated.env.linux": {
    "DISPLAY": "<your-display-value>"
}

Then close and re-open VS Code's terminal. Afterwards, running echo $DISPLAY there should output the same value as in your system terminal. This should make GUI applications launchable.

  • Related