When I try running a python code the output terminal displays the location where .py file is located in the white-colored text followed by the "&" sign and then the place where Python is installed as well as the file containing the Python code in blue text. I have no problem with the white text but earlier my VScode did not display this blue text, it's cluttering the output, is there any way to get rid of it.https://i.stack.imgur.com/CUeL4.jpg
At present, there is no direct way to omit the path information of "Terminal" in VS Code. This information shows us the path of the python interpreter used and the path of the executed file when executing the run command.
Workarounds:
Please use the setting in "launch.json": "console": "internalConsole", then click F5 to debug the code, "DEBUG CONSOLE" will only display the result.
You could use the VS Code extension "Code Runner" and use the settings in "settings.json": "code-runner.showExecutionMessage": false, then click "Run Code":
Reference: Python debug configurations in Visual Studio Code.
I have my '.py' file, and I'm running its functions on the Python Interactive Window (the notebook-like feature of VSCODE).
All the variables and functions are stored only in this Jupyter environment. They're not even accessible on the terminal.
Img that shows the variables on my Jupyter env
When I click "Debug Cell" (as you see on the img), it starts debugging using the Jupyter Environment, with all variables, but it doesn't stop on the breakpoints I've put. Like it doesn't get linked with VSCODE.
If I type F5 or click on "Run and Debug", it starts the Debug Session running the entire .py file, which is not what I want.
In this case, it can access the breakpoints, but not my variables.
I just want to debug a specific part of my code using the variables that I have already created. I must have been missing something really simple.
The only answer I can find on the internet is "you should create a launch.json file", but it doesn't fix my situation.
Does anyone know what I'm missing?
When I click "Debug Cell" in the python file, it executes the result in the "Interactive" window and can stay at the breakpoint I set, and I can also see the value of the variable executed in the code in the "Interactive" window :
Since the debugging function of python code and "Interactive" function are provided by the python extension, and the kernel function of Jupyter also depends on the Jupyter extension, please try to reinstall these two extensions and reload VS Code.
My environment:
VS Code: 1.53.1 (user setup)
python: 3.9.1
VS Code extensions: Python(2021.1.502429796); Jupyter(2020.12.414227052); Pylance(2021.2.2).
OS: Windows_NT x64 10.0.19041
In visual studion code, after installing python, I added a debug configuration provide by visual studio code (called 'current configuration') that lets me run python. I'd like the output of my executed python code to be clean and NOT show this long path every time (in blue text). How can I do this? See image attached.
Make sure that your launch.json configuration console setting is set to "internalConsole"
Unfortunately there is no way to avoid that output as it's required to launch the debugger.
Open your launch.json file and change the value of console to 'none'.
Here is the extension for python I used in the vs code: python extension.
When I use the debugging feature provided by the extension, it will hang in there and do nothing if it needs input from the command line.
Where can I input values to step over the input statement in the vs code?
The externalconsole directive is deprecated. Use console instead and indicate your preference for external this way:
"console": "externalTerminal"
The application output (and input) will go to a separate window so the VS Code debug console remains a pure python prompt where you can evaluate stuff during breakpoints.
The trick to getting this to work is on the extension's(Don Jayamanne's Python) wiki page. You have to include "externalConsole": true setting in your launch.json file's "name": "Python" section.
The extension's wiki confirms that this does not work by default:
This allows for capturing of input from the console/terminal window
applications, which isn't possible in the standard VSCode debugger.
Here are the steps to getting this to work:
From the Debug window (Ctrl+Shift+D), press the little gear icon to open (or to generate) a launch.json file. It gets placed into a .vscode directory in what ever folder you have selected as your "Open Folder" in VS Code.
You have to add pythonPath parameter to the first configuration block. This is needed to have the debugger work at all.
You also have to add and externalConsole parameter to the same block. This is what is needed to have the debugger accept input. When you debug, a separate window will open outside of VS Code but works well otherwise.
After you add both settings, the block should look something like this. I did not have to change anything else in the rest of the launch.json file.
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"program": "${file}",
"pythonPath": "C:/Users/igor/Documents/Tools/WinPython-32bit-3.4.3.7Slim/python-3.4.3/python.exe",
"externalConsole": true,
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
The console option could have any of these values: internalConsole, integratedTerminal, externalTerminal.
Normally if you start the debugger and the program stops, it leaves the external terminal displaying a prompt Press Enter to continue . . . to have access to any output of the program. If you accidentally have a syntax error the external terminal just closes not leaving any message.
When using the integratedTerminal option, the terminal stays there and displays the error message.
While I do not know if this externalTerminal thing is a bug or not, the integratedTerminal option seems to work much better in this case.
VS Code has an option for you to Debug with Python console.
You just hit Ctrl + Shift + D and beside the blue play icon, click the down arrow, and choose Python Console App instead of just Python, like this:
Updated Information on Console Options
Most of the higher-rated, original answers are no longer valid, or unclear exactly what to set and how. See below for details how to set the "Console" option in launch.json, and what all the options are.
You can choose either an internal or external terminal setting and have keyboard input work during debug. One option for output, the Debug Console, does not currently (Fall 2019) allow keyboard input to your program, although you can always use the debug console to enter live debug and code commands.
The steps to set the available options are below.
Opening the Debug Configuration launch.json file
Click the debug icon (update early 2020 - now the "Run" icon): to open the debug sidebar (again, now called the "Run" sidebar, and the command menu name is also changed from debug to run).
At the top of the screen, ensure "Python: Current File" is selected. You may need to select it or create it (might need to create your first debug/run configuration):
Click the gear icon to the right of the configuration dropdown selected in prior step. This will bring up the launch.json for that configuration in the editor.
Update the "console": option to one of the settings described below
Valid "console" settings in launch.json
"console": "internalConsole"
this is the default setting
uses the internal debug console
as of 10/2019 does not allow keyboard input.
"console": "integratedTerminal"
this spawns a new Python Debug Console terminal window every time you debug (I wish it would reuse any existing one, but it doesn't - use the trash can symbol on the upper right of the terminal window to remove old, unused terminals)
The type of terminal created is based on the default terminal type you setup (i.e. command window, bash shell, etc.).
All standard output will be in this terminal and you can enter keyboard input if the program is waiting for it.
You can switch to the DEBUG CONSOLE tab if you want to run command during debugging.
"console": "externalTerminal"
this spawns a separate terminal outside of the VS Code process as the terminal for your code to run in on run or debug.
the external terminal will be the default type for your OS (command window for Windows 10).
this terminal is separate from VS Code and will normally add a Press any key to continue... prompt after your program terminates so that you can view/copy any output before it disappears.
All standard output will go to that terminal and keyboard input can be entered in it.
You can switch to the DEBUG CONSOLE in VS Code when the code is paused to enter debug commands.
In Visual Studio Code click the pick list to the right of the green arrow. Then select Python: Terminal (external). When you launch your script it will run in an external window and allow you to key in input.
Change the launch.json and put this into your java code
{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"stopOnEntry": false,
"mainClass": "",
"args": ""
}
simply:- step1. click on small gear-icon of debugger window. step2. make "true" to this ["externalConsole": false,] in launch.json file.
step3. and just restart your debugger.
I have integrated PTVS into Visual studio so that i can have intellisense support and debugging capability.
I set Breakpoints at Function definitions, but when i debug the control goes directly out of function. And in some points the Console window pops up and it never iterates to the next line of code.
I liked PTVS but this thing has stuck me up.
In options->Python tools-> Interpreter options i have set it as Python 2.7
Can Anyone tell me whats wrong with the options and why that console screen is appearing.
Thanks in advance.
When you say you're setting breakpoint at function definitions do you mean on the line with the "def ..." or are you setting the breakpoint on the 1st statement of the function?
In Python functions are executable statements so if you're putting the breakpoint on the def line then you're going to hit the breakpoint when the function is being defined rather than being executed.
As far as the console window it will generally open unless you mark your app as a Windows application in project properties (this will launch pythonw.exe which doesn't include a console window).
If that doesn't help you might want to post the code you're having trouble with or a screenshot of the code with where the breakpoints are set.