Chapter 5: Setting up VS Code and your Python development environment
The chapter introduction explains why building an AI application requires moving beyond terminal chats to Python code and a code editor.
After this chapter you will be able to
- Python beyond terminal chats. Explain why chatting with an Ollama model in the terminal is useful for quick interactions but writing Python code is needed to build an application that calls the model programmatically.
- Code editor capabilities. Describe why a code editor is useful for writing programs, including its reading, mistake-detection, completion, and integrated-terminal features.
- VS Code development hub. Explain what VS Code is and how its editor pane and integrated terminal work together in one window.
- Homebrew casks for desktop apps. Explain why installing VS Code with Homebrew uses the --cask flag rather than the regular brew install approach for command-line tools.
- VS Code installation check. Explain that checking VS Code’s version confirms it is installed, and describe the code command as a Homebrew-created shortcut for opening VS Code from the terminal.
- Opening VS Code. Describe the two ways to open VS Code and explain why signing in is optional for this book.
- Python 3.13 installation check. Describe installing Python 3.13 with Homebrew before configuring VS Code, then checking that the reported version starts with Python 3.13. Explain why the book specifies this version even if a newer one is available.
- Python Extension Editing Aids. Explain what a VS Code extension is and how the Python extension helps while writing code through syntax highlighting, IntelliSense, and error detection.
- Python extension installation. Describe how to find and install the Python extension in VS Code, and how to tell when it is active.
- Python extension editing aids. Describe the visual and interactive help the Python extension provides when editing code: colored keywords, completion suggestions, error underlining, and hover documentation.
- Integrated terminal workflow. Explain that VS Code’s integrated terminal lets you run commands without leaving the editor, so you can see your code and its output in the same window.
- Integrated terminal controls. Describe how to toggle the terminal panel in VS Code and how to create a new terminal, using either the menu or the keyboard shortcuts.
- Tool access in VS Code. Describe how to verify that Homebrew, Ollama, and Python are accessible from VS Code’s terminal by checking that each reports its version.
- Project folder workspace setup. Describe creating a dedicated folder before writing code, opening my-ai-chatbot in VS Code, and recognizing it as the workspace root in the sidebar.
- First Python file workflow. Describe how to create hello.py in VS Code, save it, and run it from the integrated terminal. Explain that writing in the editor, saving, and running in the terminal is the workflow to repeat.
- VS Code command palette. Explain how to open the command palette and use it to find a VS Code command or setting.
What it builds on
- Interactive chat (chapter 4) · The reader has interacted with a model through chat.
- Using the terminal to interact with your computer (chapter 1) · The reader has been introduced to using a command line.
- Two ways to talk to your computer (chapter 1) · The distinction between using an interface and typing commands to the computer.
- Installing a package (chapter 2) · Using Homebrew to install a package.
- Opening the terminal on macOS (chapter 1) · The reader has previously opened and used the macOS terminal.
- Creating folders (chapter 1) · Creating a folder from the terminal.
Section by section
Introduction
The chapter introduction explains why building an AI application requires moving beyond terminal chats to Python code and a code editor.
- Python beyond terminal chats: Explain why chatting with an Ollama model in the terminal is useful for quick interactions but writing Python code is needed to build an application that calls the model programmatically.
Why it matters: This explains why the book shifts from chatting with a model to writing programs that use it. - Code editor capabilities: Describe why a code editor is useful for writing programs, including its reading, mistake-detection, completion, and integrated-terminal features.
Why it matters: These features make the editor a practical place to write and run the Python code used in later chapters.
Key terms: terminal, Ollama commands, Python code, programmatically, code editor, integrated terminal
5.1 What is VS Code?
This section introduces VS Code as a free code editor that brings writing code, running commands, and adding capabilities into one Mac development workspace.
- VS Code development hub: Explain what VS Code is and how its editor pane and integrated terminal work together in one window.
Why it matters: The editor and terminal are the two parts of the workspace you will use to write and run Python code. - Extension add-on capabilities: Describe what VS Code extensions are and give an example of a capability they can add.
Why it matters: Extensions explain how the same editor can be adapted for different development tasks.
Key terms: VS Code, code editor, editor pane, integrated terminal, extensions, add-on packages
5.2 Installing VS Code
Introduces the upcoming VS Code installation steps and tells readers who already have VS Code to skip to section 5.3.
5.2.1 Step 1: Install with Homebrew
This subsection explains why VS Code is installed through Homebrew as a cask and what to do if it is already installed.
- Homebrew casks for desktop apps: Explain why installing VS Code with Homebrew uses the --cask flag rather than the regular brew install approach for command-line tools.
Why it matters: This helps you choose the appropriate Homebrew installation option for VS Code. - Already installed VS Code: State what to do if Homebrew reports that VS Code is already installed.
Why it matters: You can move forward without repeating an installation that has already succeeded.
Key terms: Homebrew, --cask, cask, command-line tools, already installed, verification step
5.2.2 Step 2: Verify the installation
This section shows how to verify a VS Code installation and explains what the terminal shortcut and arm64 label mean.
- VS Code installation check: Explain that checking VS Code’s version confirms it is installed, and describe the code command as a Homebrew-created shortcut for opening VS Code from the terminal.
Why it matters: You can confirm the installation before trying to open VS Code from the terminal. - Native Apple Silicon label: Explain what arm64 indicates in the VS Code output and why native operation is beneficial.
Why it matters: The label helps you interpret the installation output on an Apple Silicon Mac.
Key terms: VS Code, code command, Homebrew, arm64, Apple Silicon, translation layer
5.2.3 Step 3: Open VS Code
This section shows how to open VS Code, skip an optional sign-in, and recognize the main parts of its window.
- Opening VS Code: Describe the two ways to open VS Code and explain why signing in is optional for this book.
Why it matters: You can start using the editor without creating or connecting an account. - VS Code Window Layout: Identify the sidebar, editing area, and integrated terminal in the VS Code window.
Why it matters: Recognizing the bottom panel helps you find the integrated terminal when the book uses it.
Key terms: Finder, Applications folder, terminal, Continue without signing in, Settings Sync, sidebar, editing area, bottom panel, integrated terminal
5.3 Installing Python 3.13
This section tells readers to install Python 3.13 with Homebrew and verify its version before configuring VS Code for Python.
- Python 3.13 installation check: Describe installing Python 3.13 with Homebrew before configuring VS Code, then checking that the reported version starts with Python 3.13. Explain why the book specifies this version even if a newer one is available.
Why it matters: Checking the Python version helps you use the version this book expects for its AI and audio packages.
Key terms: Homebrew, Python 3.13, python3.13 --version, patch number
5.4 Installing the Python extension
This section explains how Microsoft’s Python extension adds coding tools to VS Code.
- Python Extension Editing Aids: Explain what a VS Code extension is and how the Python extension helps while writing code through syntax highlighting, IntelliSense, and error detection.
Why it matters: These features make writing Python in VS Code easier than using it as a plain text editor. - Debugging and One-Click Running: Describe the extension’s debugger and one-click run features.
Why it matters: These tools help you run a file and investigate what its code does.
Key terms: extension, Python extension, syntax highlighting, IntelliSense, error detection, debugger, one-click run
5.4.1 Installation steps
This subsection shows how to install the Microsoft Python extension in VS Code and recognize when it is active.
- Python extension installation: Describe how to find and install the Python extension in VS Code, and how to tell when it is active.
Why it matters: Selecting the right extension and checking its status prepares VS Code for the Python work that follows.
Key terms: Extensions view, Python extension, Microsoft, Install button, gear icon
5.4.2 What you will see in practice
This section describes the help the Python extension provides while editing a Python file in VS Code and clarifies what a .py file is.
- Python extension editing aids: Describe the visual and interactive help the Python extension provides when editing code: colored keywords, completion suggestions, error underlining, and hover documentation.
Why it matters: These cues help you understand code and spot problems as you type. - Extension assistance limits: Explain how the Python extension acts as a coding assistant without writing the code for you.
Why it matters: The extension provides feedback, but you remain responsible for writing the program. - Python source file meaning: State what a .py file is in this section.
Why it matters: You will recognize what kind of file you are opening and editing when you create your first Python program.
Key terms: colored syntax, keywords, auto-completion, parameters, error underlining, linting warning, Python extension, helpful assistant, .py file, Python source file
5.5 Using the integrated terminal
The section explains how VS Code’s integrated terminal keeps command execution alongside code and output.
- Integrated terminal workflow: Explain that VS Code’s integrated terminal lets you run commands without leaving the editor, so you can see your code and its output in the same window.
Why it matters: It lets you work with commands and inspect their output alongside your code.
Key terms: integrated terminal, VS Code
5.5.1 Opening the terminal
This subsection shows how to open or create a VS Code integrated terminal and explains why it is useful for running code.
- Integrated terminal controls: Describe how to toggle the terminal panel in VS Code and how to create a new terminal, using either the menu or the keyboard shortcuts.
Why it matters: You can get to a terminal inside VS Code even if a keyboard shortcut does not work on your Mac. - Embedded macOS shell: Explain what the VS Code integrated terminal is and why having it inside the editor is useful.
Why it matters: The familiar shell is available alongside your code, so you do not need to switch applications to run it.
Key terms: terminal panel, View > Terminal, Terminal > New Terminal, integrated terminal, macOS shell, Zsh
5.5.2 Verifying your tools
This subsection verifies that Homebrew, Ollama, and Python are accessible from VS Code’s integrated terminal.
- Tool access in VS Code: Describe how to verify that Homebrew, Ollama, and Python are accessible from VS Code’s terminal by checking that each reports its version.
Why it matters: Checking from VS Code confirms that the tools are available where you will do your development work.
Key terms: VS Code’s terminal, Homebrew, Ollama, Python, version
5.6 Creating your project folder
Previews creating a chatbot project folder, opening it in VS Code, and writing, saving, and running a first Python program.
5.6.1 Setting up the workspace
This section shows how to create a dedicated project folder and open it as a VS Code workspace.
- Project folder workspace setup: Describe creating a dedicated folder before writing code, opening my-ai-chatbot in VS Code, and recognizing it as the workspace root in the sidebar.
Why it matters: Opening the project folder gives your files one organized home in VS Code.
Key terms: project folder, my-ai-chatbot, workspace root, sidebar
5.6.2 Creating and running your first file
This section walks through creating, saving, and running a first Python file in VS Code.
- First Python file workflow: Describe how to create hello.py in VS Code, save it, and run it from the integrated terminal. Explain that writing in the editor, saving, and running in the terminal is the workflow to repeat.
Why it matters: This write-save-run sequence is the basic workflow for trying your Python programs. - Python print output: Explain what the print() function does in the first program.
Why it matters: It lets you recognize what the first program is doing when it produces output.
Key terms: hello.py, .py extension, integrated terminal, Cmd-S, print(), output
5.6.3 Project structure preview
This subsection previews the project folder’s growth and shows how to find VS Code commands and settings with the command palette.
- VS Code command palette: Explain how to open the command palette and use it to find a VS Code command or setting.
Why it matters: The command palette gives you a way to find a setting or command when you are unsure where it is.
Key terms: command palette, Cmd-Shift-P
5.7 Exercises
5.8 Summary
Where this is used later
- Your first Ollama Python script (chapter 7) · The reader writes a Python script that calls an Ollama model.
- The development workflow (chapter 8) · Assumes familiarity with VS Code as the editor.
- Creating a virtual environment (chapter 6) · Creating the project environment depends on having the intended Python version available.
- Why virtual environments matter (chapter 6) · The project workspace that will receive its own environment.
- The simplest AI program (chapter 7) · Writing and running the first Ollama Python script uses the same basic workflow.
Concepts explained in this chapter
- integrated terminalA command-line interface embedded within a code editor.
- Visual Studio CodeA source-code editor developed by Microsoft with extensibility for programming workflows.
- PythonA high-level general-purpose programming language known for readable syntax and a broad software ecosystem.
- HomebrewHomebrew is a package manager for installing and managing software on macOS and other Unix-like systems.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
