Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code is not showing the ouput of Python

I am really new to Python and just started the course "Python 3 basics by Sendtex (Link: https://www.youtube.com/channel/UCfzlCWGWYyIQ0aLC5w48gBQ)".

  • I am trying to use Python with Visual Studio Code.
  • The downloaded version of Python is 3.6.4.
  • I have installed the Python extension in Visual Studio Code and have followed the procedure.

However, I am not able to get any output. Below is the attached screenshot.

Enter image description here

If I select Python it enters debugging mode. So, there isn't any output.

like image 495
sidra Aleem Avatar asked Mar 28 '18 08:03

sidra Aleem


People also ask

How do I see the output of Python in Visual Studio code?

If the installation was successful, the output window should show the version of Python that you installed. Note You can use the py -0 command in the VS Code integrated terminal to view the versions of python installed on your machine.

Why is VS Code not detecting Python?

Go to the VS Code preferences, and under interpreter, you'll find Interpreter Path , so set that to the path of your python installation, restart VS Code, and you should be good.

How do I enable VS Code in Python?

Select and activate an environment By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).


2 Answers

Using the Python Extension Run/Debug commands

Notes

  1. I recommend reviewing the official Visual Studio Code Python documentation and tutorial. That provides several of the basics, with running and debugging the "official" way.

  2. There are multiple ways to configure built-in launches:

    • When running or debugging Python in VS Code, there are a few options that you can change in your "launch.json" file. See this answer for more details.

Run or Debug with the built-in Python extension commands

You can run or debug using an icon and dropdown in the upper right of your editor window, when editing a python script file.

enter image description here

You may need to setup a run/debug configuration to use this (see below), or it may automatically step you through creating one.

The output will normally go to a new "Python" terminal in the "terminal" window (Ctrl-` to open it). See this answer for how to change that behavior.


Setting up a run/debug configuration

Easy option:

  • Use the menu item **Run/Add Configuration, and follow the prompts at the top of the VS Code window.
  • Some of the additional details are shown below.

More involved option:

  • Click the run/debug icon on the left vertical icon toolbar.
    • enter image description here
  • The window says "RUN AND DEBUG" at the top, with a drop-down that shows "No Configurations" for a given folder or workspace until you set this up.
  • The gear to the right of the dropdown will have a red dot if you need to configure this:

Enter image description here

Updated Image (1/2022) - Changed from just 'Debug' to 'Run and Debug': enter image description here

  • Click the gear icon (or in the menu, use Run/Open Configurations), and in the middle at the top, Visual Studio Code will open a window titled "Select a debug configuration".
    • The available options will depend on exactly how you have Visual Studio Code setup and configured
    • There should at least be a "Python File" option with the Python extension installed. Select it.

Enter image description here

Now your debug configuration box on the top left of the debug pane should say "Python: Current File":

Enter image description here

Visual Studio Code will add a file to your current workspace or working folder called .vscode/launch.json, and opened it for edit.

like image 64
LightCC Avatar answered Nov 15 '22 08:11

LightCC


During installation if you forget to tick in check box for path and then if you are running any python file on visual studio it will not return any output untill and unless you have not added it into visual studio code.

First of all go to FilePreferenceSettings.json

    "code-runner.executorMap":
{
  "python": "\"C:\\Program Files\\Python39\\python.exe\""

I have attached the screenshot for your better understanding!

enter image description here

like image 29
Ajeet Verma Avatar answered Nov 15 '22 06:11

Ajeet Verma