How do I setup VS Code for Python?
How to execute Python code from within Visual Studio Code - Stack Overflow
How to set up Python in VS Code? - Stack Overflow
The Ultimate VS Code Setup Guide for Python
Videos
I started learning Python as a hobby and have followed YouTube videos to start. Many recommended starting with PyCharm, so I did that and have gone through the basics and have made some basic programs like Guess the Number in PyCharm. I’ve wanted to use VS Code just because it looks nicer and is lightweight. I’ve gone on YouTube to watch videos on how to setup Vs code but the videos are not really beginner friendly. Can anyone explain how to simply setup python in vs code to get me up and running?
Here is how to configure Task Runner in Visual Studio Code to run a .py file.
In your console, press Ctrl + Shift + P (Windows) or Cmd + Shift + P (Apple). This brings up a search box where you search for "Configure Task Runner"

If this is the first time you open the "Task: Configure Task Runner", you need to select "other" at the bottom of the next selection list.
This will bring up the properties which you can then change to suit your preference. In this case you want to change the following properties;
- Change the Command property from
"tsc"(TypeScript) to"Python" - Change showOutput from
"silent"to"Always" - Change
args(Arguments) from["Helloworld.ts"]to["${file}"](filename) - Delete the last property
problemMatcher - Save the changes made

You can now open your .py file and run it nicely with the shortcut Ctrl + Shift + B (Windows) or Cmd + Shift + B (Apple).
All these answers are obsolete now.
Currently you have to:
- install the Python language extension (and Python, obviously)
- open folder (important!), open any Python file inside that folder
- switch to debug "tab"(?) and click on the gearbox (with hint 'Configure of Fix 'launch.json'')
- save the opened launch.json file (it's placed in .vscode subdirectory in the folder opened in step #2)
- finally, click the green triangle or hit F5
No additional extensions or manual launch.json editing is required now.
1) Install VS Code
2) Go to View > Command Palette
3) Type ext install and click on Install Extensions
4) Search for Python and install it
5) Reload VS
6) Start coding
This worked for me:
.vscode/settings.json:
{
"python.linting.pylintEnabled": false,
"python.pythonPath": "python.exe"
}
.vscode/tasks.json:
{
"version": "2.0.0"
}
.vscode/launch.json:
{
"version": "2.0.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"console": "internalConsole",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
You can replace "program": "${file}", with "program": "${workspaceRoot}/main.py", to run your main file no matter which file you've selected but I found that that makes errors like syntax errors sometimes not display correctly if at all.
Breaking on exceptions
- Press
CTRL + SHIFT + D - In the
BREAKPOINTSpanel, click onUncaught Exceptionsenter image description here