Home > Enterprise >  Execute Python code in an interactive shell in VS Code
Execute Python code in an interactive shell in VS Code

Time:11-06

I used to use Pyzo for Python coding and decided to give VS Code a try because it is more feature-rich. I came across one huge annoyance, however. In Pyzo, I am used to code „interactively“ as Pyzo executes code in an interactive shell (https://pyzo.org/features.html).

I would like to replicate that in VS Code, but so far had no luck. With the Microsoft Python extension installed, the closest I can come is to select the whole code, right click and then click on „Run Selection/Line in Python Terminal“. For long scripts, however, this is very, very slow as it first prints each line to the terminal and then executes it line by line. Pyzo seems to operate silently.

Do you have a solution? I think, VS Code would be much faster if it did not print each line to the terminal first.

Best

CodePudding user response:

Use Code Runner(extension available in the marketplace of VS Code) or run a bash script in the terminal (python -u {name of the file} )

CodePudding user response:

I use Python Interactive window and find it very useful. It is not an immediate REPL but gives you the time to write a block of code and execute it with a key stroke.

At the bottom of the interactive pane you have a command line where you can type like a REPL. It is a temporary cell (multi line)

  • Related