Teaching VS Code to Understand Python¶
Time required: 10-15 minutes
Prerequisites: Module 1a (VS Code installed)
What you’ll do: Install the Python extension and verify it works
Why Do We Need a Python Extension?¶
VS Code is a general-purpose text editor—it doesn’t understand Python by default. It’s like having a word processor that can display text but doesn’t know about spelling or grammar.
The Python extension teaches VS Code to understand Python code, giving you:
| Feature | What It Does | Why It Helps |
|---|---|---|
| Syntax highlighting | Colors different parts of code | Easier to read and spot errors |
| IntelliSense | Suggests code as you type | Faster coding, fewer typos |
| Error detection | Underlines problems in red | Find bugs before running code |
| Code navigation | Jump to function definitions | Understand code faster |
| Debugging | Step through code line by line | Find and fix problems |
| Jupyter support | Run notebooks in VS Code | Interactive data analysis |
Before vs. After¶
Without the Python extension:
import pandas as pd ← All text looks the same
df = pd.read_csv('data') ← No suggestions while typing
print(df.head() ← Missing parenthesis not detectedWith the Python extension:
import pandas as pd ← Keywords colored differently
df = pd.read_csv('data') ← Autocomplete suggests methods
print(df.head() ← Red underline shows the error!Installing the Python Extension¶
The Python extension by Microsoft is essential for Python development in VS Code. It provides syntax highlighting, IntelliSense, error detection, debugging, and Jupyter notebook support.
Installation¶
Follow the official VS Code documentation to install the Python extension:
Python Extension on VS Code Marketplace — Click “Install” to open VS Code and install directly
Getting Started with Python in VS Code — Complete quick start guide
Note: Make sure you install the extension simply called “Python” by Microsoft (with the blue and yellow Python logo), not “Python Extension Pack” or other variants.
What Gets Installed¶
The Python extension automatically includes:
Pylance — Fast, feature-rich language support
Python Debugger — For stepping through code
You don’t need to install these separately.
Verify the Installation¶
Let’s confirm the extension is working.
Create a Test Python File¶
Go to File → New File (or press
Ctrl+N/Cmd+Non Mac)Go to File → Save As (or press
Ctrl+S/Cmd+Son Mac)Save the file as
test.py(the.pyextension is important!)Choose any location (your Desktop is fine for now)
Test Syntax Highlighting¶
Type or paste this code into your test.py file:
# This is a comment
message = "Hello, Water Modeller!"
number = 42
print(message)What you should see:
# This is a comment— appears in a different color (often green or gray)"Hello, Water Modeller!"— the string appears in another color (often orange or brown)print— the function name is highlighted (often yellow or blue)42— numbers may have their own color
If you see different colors for different parts of the code, syntax highlighting is working!
Test IntelliSense (Autocomplete)¶
On a new line, type:
priYou should see a dropdown menu suggesting
printPress
TaborEnterto accept the suggestion
If suggestions appear as you type, IntelliSense is working!
Understand the Python Status¶
Look at the bottom-left corner of VS Code (the status bar). You might see:
“Select Python Interpreter” — Click to choose a Python version
“Python 3.x.x” — Shows which Python is selected
Nothing Python-related yet — That’s okay! We’ll set this up in Module 2b
Note: Don’t worry if you see “Select Python Interpreter” or a warning. We haven’t installed Python yet—that comes in the next modules when we set up
uv. The extension is still working correctly.
Checkpoint: Is the Python Extension Working?¶
✅ The Python extension shows as “Installed” in the Extensions view
✅ Your .py file has colored syntax highlighting
✅ Typing pri shows autocomplete suggestions
If all three are checked, the Python extension is ready!
Optional: Additional Useful Extensions¶
The Python extension is all you need to continue. However, here are some optional extensions that many water modellers find helpful:
Jupyter (Recommended)¶
What it does: Lets you run Jupyter notebooks directly in VS Code
Why it’s useful: Jupyter notebooks (.ipynb files) are great for interactive data analysis—you can run code in chunks and see results immediately. This tutorial series uses notebooks!
To install: Search for “Jupyter” by Microsoft in the Extensions view, or visit the Jupyter Extension on VS Code Marketplace
Python Indent¶
What it does: Automatically fixes Python indentation when you press Enter
Why it’s useful: Python is sensitive to indentation. This extension helps you avoid common indentation errors.
To install: Search for “Python Indent” by Kevin Rose in the Extensions view, or visit the Python Indent Extension on VS Code Marketplace
Rainbow CSV¶
What it does: Colors columns in CSV files for easier reading
Why it’s useful: As water modellers, we work with lots of CSV data. This makes viewing data files much easier.
To install: Search for “Rainbow CSV” by mechatroner in the Extensions view, or visit the Rainbow CSV Extension on VS Code Marketplace
Tip: You can always install these later. Don’t feel you need to install everything now—start simple and add extensions as you need them.
How Extensions Fit Into Your Workflow¶
As a water modeller, here’s how you’ll use these VS Code capabilities:
| Task | How VS Code + Python Extension Helps |
|---|---|
| Writing analysis scripts | Autocomplete suggests pandas/numpy methods |
| Reading colleague’s code | Syntax highlighting makes it readable |
| Finding bugs | Red underlines show errors before you run |
| Learning new packages | Hover over functions to see documentation |
| Running notebooks | Jupyter extension lets you work interactively |
Example: The Extension Helps You Learn¶
When you’re learning pandas (a data analysis package), the extension helps:
You type
df.(wheredfis a DataFrame)A list appears showing all available methods:
.head(),.describe(),.plot(), etc.Hover over any method to see what it does
Select one and it’s inserted with correct syntax
This means you don’t need to memorize every function—VS Code helps you discover them!
Troubleshooting¶
“I don’t see any syntax highlighting”¶
Make sure your file is saved with a
.pyextensionCheck the bottom-right corner of VS Code—it should say “Python”
If it says “Plain Text”, click it and select “Python”
“The extension won’t install”¶
Check your internet connection
Try restarting VS Code
On work computers, your IT department may need to allow VS Code marketplace access
“I see an error about Python not being installed”¶
This is expected! We haven’t installed Python yet. The extension is working correctly—it’s just telling you that Python itself isn’t set up. We’ll fix this in Module 2b when we install uv.
“IntelliSense suggestions are slow or don’t appear”¶
Wait a few seconds after opening a file—the extension needs time to analyze your code
Make sure Pylance is enabled (it’s included with the Python extension)
Try pressing
Ctrl+Spaceto manually trigger suggestions
Clean Up (Optional)¶
You can delete the test.py file we created—it was just for testing. Or keep it as a scratch file for experiments!
To delete:
Find the file in VS Code’s Explorer (left sidebar)
Right-click → Delete (Mac: Control-click or two-finger click)
Or just delete it from your file manager (File Explorer on Windows / Finder on Mac)
Summary¶
In this module, you:
✅ Learned why the Python extension is essential
✅ Installed the official Python extension by Microsoft
✅ Verified syntax highlighting and IntelliSense work
✅ (Optionally) Learned about additional helpful extensions
What You Now Have¶
VS Code ✅
└── Python Extension ✅
├── Syntax Highlighting ✅
├── IntelliSense ✅
├── Error Detection ✅
└── Debugging ✅What’s Missing?¶
We have VS Code ready for Python, but we don’t have Python itself installed yet! In the next modules, we’ll:
Module 2a: Understand why we need environment management
Module 2b: Install
uv(which will install Python for us!)
Ready? Continue to Module 2a: Understanding Environment Management