9

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?

5 Answers 5

14

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

Sign up to request clarification or add additional context in comments.

2 Comments

@xnegra80 This should probably be the accepted answer.
ALTERNATIVE: VS Code "Tasks" add this to settings.json file: "tasks": [{"label": "Terminal: Python", "type": "shell", "command": "{../python.exe}","args": ["-i","py_file.py"] }] (in file
7

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

Comments

4

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

1 Comment

It opens jupyter which I dont think is what I wanted. Any ways to fix that?
2

To build on the answer already provided, you can automatically run in interactive mode by changing your settings:

Go under File>Preferences>Settings. Search for "arguments" in the search bar. Then under "Python › Terminal: Launch Args", click on the link "Edit in settings.json". Once settings.json is open, add "-i" with the quotation marks. It should look something like that:

{
    "workbench.colorTheme": "Default High Contrast",
    "terminal.integrated.localEchoEnabled": "off",
    "terminal.integrated.shellIntegration.enabled": false,
    "python.terminal.launchArgs": [
    "-i"
    ]
}

Now, it will pass the argument -i every time you run.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.