Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open the interactive shell/REPL in Visual Studio Code?

I'm using Visual Studio Code, and I'd like to have a REPL that I can run single Python instructions in. I've found some year-old Microsoft documentation on this that says select the View > Other Windows > Interactive menu item, but there is no Other Windows item in my version of VS Code (1.44.2).

Does VS Code have a REPL feature, or do I have to run python.exe directly from the Terminal pane?

like image 392
Al Sweigart Avatar asked Sep 06 '25 03:09

Al Sweigart


2 Answers

You are looking at the wrong documentation. That's for Visual Studio, not Visual Studio Code. They are annoyingly similarly named, which can be confusing, but they are two completely different IDEs.

The correct docs for VS Code is here:
https://code.visualstudio.com/docs/languages/python

There is a section for running Python codes on the Terminal:
https://code.visualstudio.com/docs/languages/python#_run-python-code

You can use the standard Python console.

  1. Install the Python extension for VS Code
  2. Setup and select the correct Python environment
    • Open the Command Palette then "Python: Select Interpreter" enter image description here
  3. Next, highlight the line you want to run, then right-click
  4. Select the Run Selection/Line in Python Terminal enter image description here
  5. It should open up a Terminal panel and run your code in Python console enter image description here
  6. You can then keep right-clicking > Run and it will execute on the same session

There's also an option to run the entire file.

See the Run Python Code section of the docs for more info.

like image 126
Gino Mempin Avatar answered Sep 07 '25 19:09

Gino Mempin


enter image description here

You can open the command palette and enter python: Start REPL

This will open the REPL.

like image 34
UJJWAL KESHRI Avatar answered Sep 07 '25 21:09

UJJWAL KESHRI