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.
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
I am trying to run python script
from selenium import webdriver
from pyvirtualdisplay import Display
Display(visible=1, size=(800, 600)).start()
driver = webdriver.Chrome(options=option)
driver.get("https://google.com")
but I am getting error "Xephyr cannot open host display. Is DISPLAY set?
It's minimal ubuntu 18.04 installation with x11 installed
also chromium-browser works only when I type startx chromium-browser, otherwise it's drop Trace/breakpoint trap (core dumped)
#update
when I run sudo xinit and run my script manually it works but in window, not fullscreen, are there another way to run it?
#update
I was trying to set options in python script to run fullscreen like "--start-fullscreen" and "--start-maximized" but it cover half of screen like here: https://unix.stackexchange.com/questions/273989/how-can-i-make-chromium-start-full-screen-under-x
also I was trying to edit Preferences for chromium like in this thread in /home//.config/chromium/Default/Preferences, but its not working, I saw that every run of my python script chromium generate new Preferences in /tmp/.org.chromium.Chromium./Default/Preferences this browser setting are different than these in /home//.config/(...)/Preferences
ofc I have delete Display option from python script
Any help?
I am having a problem using terminal in a Linux VirtualBox Terminal. This terminal is being used to compliment the StanfordOnline "Compilers" course on edX, the language for the class is called "cool".
Within this terminal I used the command "emacs 1.cl" in order to open the file "1.cl" with emacs. After I enter this command the file is successfully opened but the command prompt does not reappear, instead everything I type is just greyed text (see screenshot - Terminal is black window on left).
Why is this happening? I can start typing commands again if I close and then re-open terminal, but I think there must be a reason why this happens. Anyone have an idea?
Thanks in advance, let me know if I can provide any more helpful information regarding the course or the software. Running VirtualBox on MacOS Catalina 10.15.4 if it makes any difference.
-DR
Screenshot
I am currently using Atom to code in Python3 on my Mac and I have a package installed ("atom-python-run") which launches a terminal window with the command "python3 {path}" with 'path' being the current working directory with filename.py included. It opens just fine and runs perfectly, but the window doesn't open on top of my atom window but behind it instead. I have to click it every time to see the terminal window and it's really frustrating. I also hate using CMD+Tab to find it as well.
This is a bug in the package I'm using (I think) and I don't want to wait for them to fix it. Are there any methods in OS X to ALWAYS open Terminal on top of every other window? Or a third-party application? I can't find a solution to this problem anywhere online.
If you install the scripts package and use it, the output will be written to a window in the Atom application and will be shown at completion. Go to the Atom package page and search for the word script. You should get a hit on the "script" package. Install this package by just clicking on the install button and then open Atom and the python script you wish to run. Now in Atom go to the packages menu item and from that menu select "script". You'll be given several options, choose "run script" and your script should run showing the output in a window at the bottom of the Atom window.
I am working on a text adventure with python and the issue i am having is getting spyder to open a interactive cmd window. so far i have tried os.systems('cmd / k') to try and open this which it did but i could not get any code to run and kept getting an app could not run this file error. my current code runs off a import module that pulls the actual adventure from another source code file. how can i make it to where only one file runs and opens the cmd window to play the text adventure?
(Spyder maintainer here) Cmd windows are hidden by default because there are some packages that open lot of them while running code (e.g. pyomo).
To change this behavior, you need to go to
Tools > Preferences > IPython console > Advanced settings > Windows adjustments
and deactivate the option called Hide command line output windows generated by the subprocess module.
I found myself in a similar situation, developing code for a research group with heavy Spyder usage. I came up with this workaround to force usage of the vanilla Popen class regardless of whether or not it is run from Spyder (full disclosure I have not tested it very aggressively):
import subprocess
try:
from spydercustomize import SubprocessPopen
except ImportError:
SubprocessPopen = subprocess.Popen
else:
SubprocessPopen = SubprocessPopen.__bases__[0]
process = SubprocessPopen()
I am using Python Enthought Canopy. Each time I initiate the editor, I have to change the working directory by typing the code:
import os
os.chdir('C:/Users/Name/Canopy/scripts')
This is quite tedious as the directories are all reset after I quit the editor and start again.
Is there a way that I can change the default working directory, or change the profile of Canopy such that each time the settings will be run before coding?
1) Canopy's GUI is not IDLE.
2) Since this is ipython and has access to ipython magics, you can just type cd ~/Canopy/scripts with no import.
3) But I'm guessing that you have at least one script open in the editor. So you might prefer to just keep the directory synced to the editor, see http://docs.enthought.com/canopy/2.1/quick-start/code_editor.html#change-directory
4) All of the above said, yes you can run arbitrary code on ipython startup. See Ipython Notebook: Default Initialization Python Code