Bar Akiva
Bar Akiva

Reputation: 1209

Executing Python code in VScode outputs Python PATH and project's absolute path to console

When I execute a simple print('Hello world') by using "Run Python File" in VScode I get this output

barakiva@pop-os:~/Development/Educational/Languages/Python/lang$ /usr/bin/python3 
/home/barakiva/Development/Educational/Languages/Python/lang/vars.py Hello world

However, opening VScode's integrated console and typing python3 vars.py outputs normally with no clutter

barakiva@pop-os:~/Development/Educational/Languages/Python/lang$ python3 vars.py
Hello world

Upvotes: 0

Views: 875

Answers (1)

Dorin Botan
Dorin Botan

Reputation: 1378

This happens because the code is run through the Terminal. In short, under the hood, VSCode opens a new terminal and executes the command to run your program using the full path. It's done this way to avoid possible conflicts, if you choose to e.g. use an external terminal with a custom configuration.

VSCode can also display the program output only, via the Debug Console (tab to the left from Terminal). To do this, you need to create a custom launch configuration.

In the Run and Debug tab click create a launch.json file (if you don't have one already) and select the Python File template. Then, in .vscode/launch.json change property "console": "integratedTerminal", to "console": "internalConsole" for the desired configuration. See the complete config below:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "internalConsole",
            "justMyCode": true
        }
    ]
}

With this in place, you can run your Python file like before, and see the program output in the Debug Console:

enter image description here

Upvotes: 1

Related Questions