Run Python in VSCode in python shell like IDLE

Viewed 8450

I am well aware of the thread How to execute Python code from within Visual Studio Code

But none of them shows how to get the >>> python shell running with the file imported. Cuz I would like to call functions separately. I understand that I can get the python shell going by simply typling python in the terminal but the functions in the python file have to manually imported everytime.

Is there a way to run files in VSCode like in IDLE?

4 Answers

you can run the file in an interactive mode in VSC code terminal by using the parameter -i : python -i py_file.py

Install the Python Extension, then press Ctrl+Shift+P (Command+Shift+P) and type Python: Start REPL. Click the command, and you'll get an interactive Python console.

enter image description here

Assuming you have the official Python extension installed, you can search the command list (Ctrl+Shift+P) for "Python interactive" and you'll see several options that allow to do different variations of this:

python interactive

Not sure if this was figured out or not, but I was having a similar question. How to simply use something like IDLE (the known '>>>' shell prompt) inside VSCodesee w/o chasing down plugins and their settings? I noticed that no answer was marked confirmed and although insightful, not what I was looking for.

I use Mac and while trying different things to address this, I found that by using/copying the path in the Python Launcher settings I got what I was looking for. Then, I validated the equivalent for Windows. Please see below.

Windows: If you are using Windows, from your Terminal pane/window in VSCode, enter the path to your python.exe, including the executable name. It is located within the "User > AppData" directory.

For example: C:\Users\YOUR_USER_ID\AppData\Local\Programs\Python\Python310\python.exe

Note that AppData is a hidden folder, so may have to change your view settings in Explorer to show Hidden Items.

MAC: If you are using MAC, from your Terminal pane/window in VSCode, enter the path to your interpreter

For example: /usr/local/bin/python3

Note: You can also do this directly from a CMD, PowerShell or a Terminal(Mac) window without having to launch IDLE, VSCode or any other coding/scripting app.

Related