Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Module 1b: Python Extension Setup

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:

FeatureWhat It DoesWhy It Helps
Syntax highlightingColors different parts of codeEasier to read and spot errors
IntelliSenseSuggests code as you typeFaster coding, fewer typos
Error detectionUnderlines problems in redFind bugs before running code
Code navigationJump to function definitionsUnderstand code faster
DebuggingStep through code line by lineFind and fix problems
Jupyter supportRun notebooks in VS CodeInteractive 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 detected

With 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:

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

  1. Go to File → New File (or press Ctrl+N / Cmd+N on Mac)

  2. Go to File → Save As (or press Ctrl+S / Cmd+S on Mac)

  3. Save the file as test.py (the .py extension is important!)

  4. 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)

  1. On a new line, type: pri

  2. You should see a dropdown menu suggesting print

  3. Press Tab or Enter to 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:

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:

TaskHow VS Code + Python Extension Helps
Writing analysis scriptsAutocomplete suggests pandas/numpy methods
Reading colleague’s codeSyntax highlighting makes it readable
Finding bugsRed underlines show errors before you run
Learning new packagesHover over functions to see documentation
Running notebooksJupyter extension lets you work interactively

Example: The Extension Helps You Learn

When you’re learning pandas (a data analysis package), the extension helps:

  1. You type df. (where df is a DataFrame)

  2. A list appears showing all available methods: .head(), .describe(), .plot(), etc.

  3. Hover over any method to see what it does

  4. 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 .py extension

  • Check 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+Space to 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:

  1. Find the file in VS Code’s Explorer (left sidebar)

  2. Right-click → Delete (Mac: Control-click or two-finger click)

  3. 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:

  1. Module 2a: Understand why we need environment management

  2. Module 2b: Install uv (which will install Python for us!)


Ready? Continue to Module 2a: Understanding Environment Management