Configure VS Code for Python — extensions, settings and the run button explained (and the typo Pylance spotted before I did)
My first program in VS Code was three lines long and it still failed. I pressed the run button, the terminal filled with red and at the bottom it said NameError: name 'pirnt' is not defined. I’d typed pirnt instead of print. The funny thing is that VS Code had already warned me: the word had been underlined with a wavy line for a while and I hadn’t looked. That day I understood that a well-configured editor isn’t a luxury: it’s a teammate that checks what you write while you write it.
Configuring VS Code for Python properly is the first thing you should do before writing a single line of code on your computer. When I started practising on my own, it took me days to get it comfortable because nobody told me which extensions to install or which settings to change. Here’s what I use, no fluff, with what each piece does and how to fix what usually goes wrong.
Table of Contents
What is VS Code and why don’t we just use Python’s IDLE?
Python comes with its own editor, IDLE, but it’s basic: it colours the code and not much more. VS Code (Visual Studio Code) is a free, professional editor from Microsoft used by everyone from students to company teams. With the right extensions it autocompletes, flags errors before you run, debugs step by step, opens Jupyter notebooks and works with Git. During the degree you’ll use it for Python, C and Java, so learning it properly from the start is time well spent.
| IDLE | VS Code | |
|---|---|---|
| Autocomplete | Very basic | Complete (Pylance) |
| Errors before running | No | Yes, underlined |
| Debugger | Simple | Breakpoints, variables, call stack |
.ipynb notebooks | No | Yes (Jupyter extension) |
| Other languages (C, Java) | No | Yes |
VS Code and Visual Studio are two different programs. Visual Studio (without “Code”) is a huge environment for C# and C++; for your degree you want VS Code.
Before you start: what you need
Make sure you have:
- Python installed and working in the terminal (
python --versionanswers). If not, follow the guide on how to install Python on Windows first. - Windows 10 or 11 (VS Code also exists for macOS and Linux; the steps are almost identical).
- A folder for your degree, for example
C:\Users\YourName\GCID\FP1. In step 4 you’ll see why it matters so much.
If any of these sounds doubtful, sort it out before going on: 90% of VS Code problems come from a badly installed Python.
Anything that depends on Windows (installer, menus, terminal messages) is described as it appears in the official VS Code documentation and on my machine; the two Python programs in this article have been run and their output is real.
Step 1 — Download and install
Go to code.visualstudio.com and click the download button for Windows.

Download the User Installer (the default one): it installs just for your user and doesn’t ask for administrator rights. The installation is next, next, next, and there are no tricks here like with Python, but on the additional tasks screen I recommend ticking:
- Add “Open with Code” action to the context menu for files and folders: you’ll be able to right-click a subject folder and open it directly.
- Add to PATH (ticked by default): lets you open VS Code from the terminal with
code ..
With “Add to PATH” ticked, go into an assignment folder from the terminal and type code . (with the dot): VS Code opens with that folder. The dot means “the folder I’m in”.
Step 2 — Essential extensions to configure VS Code for Python
This is what really matters. VS Code without extensions is a tasteful text editor; with them, a programming environment. Press Ctrl + Shift + X (or the squares icon in the left bar), search for each one and install it:

Python (by Microsoft). Essential. Check that the author is Microsoft: there are many with similar names. Installing it also installs three more by themselves:
- Pylance: autocomplete, documentation on hover and errors marked as you type (the underline I ignored).
- Python Debugger: step-by-step debugging with breakpoints (covered in depth in Python debugging).
- Python Environments: creating and choosing virtual environments (
.venv). According to its Marketplace page it’s still rolling out, so you may not see its panel yet; everything in this guide works the same either way.
As the diagram shows, a single search (“Python”) gives you three tools. The ones at the bottom are your choice:
- Jupyter (by Microsoft): opens and runs
.ipynbnotebooks cell by cell without leaving VS Code. In statistics and data science you’ll use them constantly. - Rainbow CSV: colours each column of a
.csvfile. It seems trivial until you have a 30-column CSV in front of you. - Black Formatter (by Microsoft): tidies your code on save (spaces, line breaks, quotes). It’s what makes the “Format On Save” setting in step 3 work.
- indent-rainbow (optional): colours indentation levels. In Python indentation is part of the code, and this extension makes it very obvious when a line is one level off.
Installing extensions from unknown authors that promise “all-in-one Python”. They can clash with Pylance (two autocompletes at once) or ask for odd permissions. Microsoft’s ones plus this list are more than enough.
Step 3 — Key settings to configure VS Code for Python
Open settings with Ctrl + , and search for each setting by name:
- Auto Save →
afterDelay. VS Code saves by itself every second; you’ll never again run an old version because you forgot to save. - Font Size → 14, 15 or 16. The default is small and after two hours your eyes notice.
- Format On Save → on. Every time you save, Black tidies your code.
- Default Formatter for Python → Black Formatter. Without this step, “Format On Save” does nothing with
.pyfiles, because VS Code doesn’t know what to format with.
If you prefer, the same settings can be written directly in settings.json (Ctrl + Shift + P → Preferences: Open User Settings (JSON)):
{
"files.autoSave": "afterDelay",
"editor.fontSize": 15,
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
The "[python]" section means “for Python files only”: that way, when you program in C or Java, that formatter stays out of it. Watch the commas: in JSON they go between items, never after the last one (I checked this block with a JSON parser so it has no extra ones).
With afterDelay the file saves itself, but “Format On Save” only kicks in when you save yourself with Ctrl + S. Get used to pressing it now and then and you’ll see the code rearrange itself.
Step 4 — Connect it to Python
Here’s the step most people skip: open the folder, not the file. Go to File > Open Folder and choose the subject folder, for example GCID\FP1. With a folder open, VS Code has a “workspace”: it remembers which Python to use, keeps its own settings and detects any virtual environments inside.
Create the virtual environment (.venv)
A virtual environment is a lightweight copy of Python just for that folder, with its own pip. That way, one subject’s libraries don’t mix with another’s. To create it:
Ctrl + Shift + P→ Python: Create Environment.- Choose Venv and then the Python you installed (for example 3.15.2).
- Wait a few seconds: the
.venvfolder appears in the explorer.
When you open a terminal in VS Code, PowerShell answers that “running scripts is disabled on this system” and doesn’t activate the environment. It’s a Windows protection. Fix it for your user only with Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser in PowerShell, or choose Command Prompt as the default terminal (Ctrl + Shift + P → Terminal: Select Default Profile).
Choose the interpreter
Inside the folder, create a subfolder for the topic and the file test.py. At the bottom right, in the status bar, you’ll see the Python version VS Code is using. If it isn’t yours (or it says “Select Interpreter”), click there or use Ctrl + Shift + P → Python: Select Interpreter and pick the .venv one.

Run your first program
Write this in test.py:
# test.py: the program that checks VS Code is running your Python
name = "Sergio"
subjects = ["FP1", "Calculus", "Algebra"] # a list with three strings
print(f"Hello, {name}. Welcome to VS Code.")
print(f"This term you have {len(subjects)} subjects:")
for s in subjects: # the indentation (4 spaces) marks what repeats
print(" -", s)
Press the run button, the triangle at the top right (Run Python File). The terminal opens at the bottom and shows:
Hello, Sergio. Welcome to VS Code. This term you have 3 subjects: - FP1 - Calculus - Algebra
Quick check: the list holds three strings, so len(subjects) is 3, and the for prints one line per subject, each with two spaces and a dash in front. If you get this, you’re all set.
What exactly happened when you pressed the run button? It’s in the diagram:
VS Code doesn’t run anything “by magic”: it types python test.py in the terminal using the interpreter you chose in the status bar. On Windows you’ll see something like & C:/Users/YourName/GCID/FP1/.venv/Scripts/python.exe c:/Users/YourName/GCID/FP1/topic_variables/test.py: the full path of the environment’s python.exe and of the file. If the interpreter in the status bar isn’t yours, the program runs with another Python and the imports of the libraries you installed fail.
Check that Pylance warns you
Now repeat my anecdote on purpose. Create typo.py with this code:
# typo.py: a misspelt name that Pylance underlines BEFORE you run it
name = "Sergio"
pirnt(f"Hello, {name}") # print misspelt: pirnt
Before running it, look at line 3: pirnt is underlined and, when you hover over it, Pylance says "pirnt" is not defined. That’s the sign Pylance is working. If you run it with the run button anyway, this is what appears in the terminal:
Traceback (most recent call last):
File "typo.py", line 3, in <module>
pirnt(f"Hello, {name}") # print misspelt: pirnt
^^^^^
NameError: name 'pirnt' is not defined. Did you mean: 'print'?
Read the traceback from the bottom up: the last line says what happened (NameError: that name doesn’t exist) and even suggests the fix (Did you mean: 'print'?); the line above says where (line 3) and the little arrows ^^^^^ point at the exact word. If you don’t see the underline before running, check that the Python extension is installed and that the status bar shows an interpreter.
Ctrl + Shift + M opens the Problems panel with all of Pylance’s warnings for the project. Before submitting an assignment, take a look: if it’s empty, even better.
Notebooks (.ipynb) in VS Code
In statistics and the data subjects you’ll work with notebooks (.ipynb): documents that mix code cells, their output and text. With the Jupyter extension you open them directly in VS Code:
Ctrl + Shift + P→ Create: New Jupyter Notebook (or open an.ipynbsomeone gives you).- At the top right click Select Kernel and choose the Python in your
.venv. A notebook’s “kernel” is the Python that runs its cells (nothing to do with the Linux kernel). - The first time, VS Code will ask to install the
ipykernelpackage in that environment: accept. - Type in a cell and press
Shift + Enterto run it and move to the next one.
A notebook’s variables stay alive between cells while the kernel is running. If something gives strange results, Restart the kernel and run the cells in order from top to bottom: often the problem is having run an old cell.
Keyboard shortcuts that save you hours
You don’t need to learn them all on day one. With these nine (Windows, US layout; the Spanish layout equivalents are in the note below) you’ll already work twice as fast:
| Shortcut | What it does |
|---|---|
Ctrl + Shift + P | Command palette: search any action by name |
Ctrl + P | Open a file in the folder by typing part of its name |
| Ctrl + backtick | Show or hide the integrated terminal |
Ctrl + S | Save (and format, if you turned on Format On Save) |
Ctrl + / | Comment or uncomment the selected lines |
Alt + ↑ / Alt + ↓ | Move the current line up or down |
F2 | Rename a variable across the file |
F5 | Start debugging |
Ctrl + Shift + M | Problems panel with Pylance’s warnings |
On a Spanish keyboard the backtick and slash keys are elsewhere, so VS Code maps the terminal to Ctrl + ñ and commenting to Ctrl + }. If one doesn’t work for you, look it up in File > Preferences > Keyboard Shortcuts.
Final check: is everything ready?
Before calling the setup done, go through this list:
- Does VS Code open the subject folder (not a loose file)?
- Do you have Python, Pylance, Python Debugger and, if you’ll use them, Jupyter and Black Formatter installed?
- Does the status bar show the Python in your
.venv? - Does the run button run
test.pyand print the output above? - Does Pylance underline
pirntintypo.pybefore you run it? - When you press
Ctrl + S, does the code get reformatted?
If you said yes to all six, your environment is just like mine.
Common problems and how to fix them
No interpreter appears in the list. VS Code can’t find Python. Check in a terminal outside VS Code that python --version works, close VS Code completely and open it again.
The run button uses a different Python. Look at the status bar: the chosen interpreter is in charge. Change it with Python: Select Interpreter.
ModuleNotFoundError: No module named 'numpy' even though you installed it. You installed it into another Python. Open a terminal inside VS Code, which already has the environment activated, and run python -m pip install numpy.
“Format On Save” does nothing. The default formatter for Python (Black Formatter) is missing or the extension isn’t installed.
The imports are underlined in yellow (“could not be resolved”). Same root cause: Pylance looks at the chosen interpreter and that library isn’t in it.
The terminal doesn’t recognise python. If you’ve just installed Python with VS Code open, the integrated terminal keeps the old PATH. Close VS Code entirely and open it again.
| Symptom | Likely cause |
|---|---|
| No interpreters in the list | Python badly installed or VS Code opened before installing |
ModuleNotFoundError | Library installed in another Python |
| Format On Save does nothing | No default formatter |
pirnt not underlined | Python extension not installed or no interpreter |
| Scripts disabled in PowerShell | Windows execution policy |
What’s next?
With Python installed and VS Code configured you have the environment ready for your entire degree. Three ideas to take away:
- Open folders, not loose files, and one folder per subject with its own
.venv. - The interpreter in the status bar is in charge: it’s the one the run button, Pylance and pip use.
- Read the underlines before running: Pylance saves you errors the terminal only shows afterwards.
In the next article we get into the interesting stuff: variables and data types in Python, what each variable stores and why Python thinks differently from other languages. And whenever you want to watch your program line by line, the debugger you just installed is explained in Python debugging.
Keep goingAll Tools articlesDid this article help you? Here is how you can support SergioLearns →



