Getting Started· 15 min

VS Code Setup

What you'll learn
  • Install VS Code and the Python extension
  • Select the .venv interpreter for each session folder
  • Run scripts from the integrated terminal and the Run button
  • Use breakpoints and the Python debugger

VS Code is the recommended editor for this course. It gives you syntax highlighting, a one-click run button, a built-in terminal, and a proper Python debugger — everything you need to move fast during the hands-on sessions.

Prerequisite
Complete the Overview and API Keys pages first so you have Python, a .venv, and a .env file ready.

Step 1 — Install VS Code

  1. Download from https://code.visualstudio.com/download
  2. Run the installer (accept the defaults).
  3. On Windows, check "Add to PATH" and "Register Code as editor for supported file types" during install.
  4. Open VS Code once to finish initial setup.

Step 2 — Install the Python extension

The official Python extension from Microsoft gives you interpreter selection, linting, debugging, and the Run button on each file.

  1. Click the Extensions icon in the left sidebar (or press Ctrl+Shift+X / Cmd+Shift+X).
  2. Search for "Python" — the publisher should be "Microsoft".
  3. Click Install.
  4. Also recommended: "Pylance" (auto-installed with Python) and "Python Debugger".

Step 3 — Open the course folder

Open the session folder you want to work in — not the parent AICourse folder. Each session has its own .venv and .env, and VS Code's Python extension picks them up per folder.

  1. File → Open Folder (or Cmd+O / Ctrl+K Ctrl+O).
  2. Select a session folder, e.g. AICourse/Session1.
  3. If prompted "Do you trust the authors of the files?" — click Yes.
Quick tip
From any terminal you can run "code ." inside a folder to open it in VS Code instantly.

Step 4 — Select the Python interpreter (.venv)

This is the single most important step. VS Code needs to know which Python to use. Point it at the .venv you created in the Overview page so it gets all the installed packages.

  1. Open any .py file in the folder (e.g. src/01_text_basic.py).
  2. Press Ctrl+Shift+P (Cmd+Shift+P on macOS) to open the Command Palette.
  3. Type "Python: Select Interpreter" and press Enter.
  4. Choose the one labelled ('.venv': venv) — it should have a star or "Recommended" next to it.
How to tell it worked
Check the bottom-right of the VS Code window — it should show "Python 3.12.x ('.venv')" or similar. If it still says "Select Interpreter", repeat the step.

Step 5 — Open the integrated terminal

You will run the exercise scripts from the terminal inside VS Code, not a separate window. VS Code will auto-activate your .venv in new terminals once you have selected the interpreter.

  1. Open the terminal with Ctrl+` (backtick) or View → Terminal.
  2. Check the prompt starts with (.venv). If not, activate it manually: source .venv/bin/activate (macOS/Linux) or .\.venv\Scripts\Activate.ps1 (Windows).
  3. Verify: which python (macOS/Linux) or where python (Windows) — it should point inside .venv.

Step 6 — Run a script (two ways)

Option A — Run button

Open any .py file and click the ▶ triangle at the top-right of the editor. VS Code runs it in the terminal using your selected interpreter. Fastest for scripts that need no arguments.

Option B — Terminal command (recommended for CLI scripts)

Many exercises take command-line arguments like --prompt. For those, run them from the integrated terminal:

$ python src/01_text_basic.py --prompt "Give me 3 startup ideas"

Step 7 — Load environment variables from .env

Every script calls load_dotenv() internally, so .env is picked up automatically when you run from the terminal. But when you use the Run button or the debugger, VS Code can also read it if you point it at .env in the Python extension settings.

.vscode/settings.json (optional)
{
  "python.envFile": "${workspaceFolder}/.env",
  "python.terminal.activateEnvironment": true
}
This file is optional — the scripts already load .env themselves via python-dotenv.

Step 8 — Use the debugger (optional but powerful)

  1. Click the left margin next to a line number to set a breakpoint (red dot).
  2. Press F5 to start debugging.
  3. When prompted "Debug Configuration", pick "Python File".
  4. Execution pauses at your breakpoint — inspect variables in the left panel.
  5. Step through with F10 (over) and F11 (into).
Breakpoint before response.output_text
Set a breakpoint right after response = client.responses.create(...) to inspect the full API response object. Great for learning what the SDK actually returns.

Recommended extensions (nice-to-have)

  • Python (Microsoft) — required
  • Pylance — faster IntelliSense
  • Ruff — fast linter for Python
  • GitLens — supercharged git integration
  • Error Lens — inline error messages
  • DotENV — syntax highlighting for .env files

Common problems

ModuleNotFoundError: No module named 'openai'
VS Code is using the wrong interpreter. Repeat Step 4 and pick the .venv one. Then close and reopen the terminal.
API key missing error
Make sure .env exists in the same folder you opened (Session1, Session5, etc.) and that it contains OPENAI_API_KEY=... with no quotes.
Run button runs the wrong Python
Click the interpreter name in the bottom-right status bar and reselect the .venv one. Then click Run again.
You are ready
With VS Code, the .venv interpreter, and the integrated terminal set up, every exercise in the course is a one-click or one-command away. Head back to the Overview and start Session 1.