Foundations · Module 4

Setting up your environment

Python is the language of AI development.

35 min 4 outcomes Foundations

Previously

Your computer's command line

I know the command line can look intimidating.

This module

Setting up your environment

Python is the language of AI development.

Next

Your first AI interaction

Let us have your first conversation with a local AI model.

Progress

Mark this module complete when you can explain it without rereading every paragraph.

Why this matters

A virtual environment is an isolated space for your project's dependencies.

What you will be able to do

  • 1 Install Python and confirm it runs from the terminal.
  • 2 Create and activate a virtual environment for a project.
  • 3 Install and run Ollama so you can use a local model safely.
  • 4 Set up VS Code so editing and running scripts feels straightforward.

Before you begin

  • No previous technical background required
  • Read the section explanation before using tools

Common ways people get this wrong

  • Works on my machine. Unpinned dependencies make local success meaningless.
  • Secret leakage. If a key reaches a repo or client logs, treat it as compromised and rotate it.

1.4.1 Installing Python

Python is the language of AI development. Almost every AI framework, library, and tool is written in or has bindings for Python. Let us install it.

On macOS:

# Check if Python is already installed
python3 --version

# If not, install using Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install python@3.12

On Windows:

  1. Go to python.org/downloads

  2. Download Python 3.12 or later

  3. Run the installer

  4. Important: Check "Add Python to PATH" before clicking Install

Verify the installation:

python3 --version
# Should output something like: Python 3.12.x

1.4.2 Virtual Environments

A virtual environment is an isolated space for your project's dependencies. Without it, different projects might conflict with each other.

Creating a virtual environment:

# Navigate to your project folder
cd my-ai-project

# Create the environment
python3 -m venv venv

# Activate it (macOS/Linux)
source venv/bin/activate

# Activate it (Windows)
.\venv\Scripts\activate

When activated, you will see (venv) at the start of your prompt. This means you are inside the virtual environment.

1.4.3 Installing Ollama

Ollama lets you run powerful AI models locally on your own computer. No API keys needed. No data leaving your machine. Free and private.

On macOS:

# Using Homebrew
brew install ollama

# Or download from ollama.com

On Windows:

  1. Go to ollama.com/download

  2. Download and run the Windows installer

  3. Follow the setup wizard

Verify the installation:

ollama --version

Download your first model:

# Start the Ollama server (runs in background)
ollama serve

# In a new terminal, download a model
ollama pull llama3.2:3b

This downloads the Llama 3.2 model with 3 billion parameters. It is about 2GB and runs well on most modern computers.

Mental model

Reproducible environments

A good environment setup makes builds repeatable and keeps secrets out of the codebase.

  1. 1

    Code

  2. 2

    Dependencies

  3. 3

    Configuration

  4. 4

    Environment

  5. 5

    Run and test

Assumptions to keep in mind

  • Versions are pinned. Pin versions so the same code behaves the same next week and in CI.
  • Secrets are separated. Secrets live in an environment store, not in commits, screenshots, or logs.

Failure modes to notice

  • Works on my machine. Unpinned dependencies make local success meaningless.
  • Secret leakage. If a key reaches a repo or client logs, treat it as compromised and rotate it.

Check yourself

Quick check. Your environment setup

0 of 4 opened

Why use a virtual environment for a Python project

It keeps dependencies isolated so different projects do not break each other.

Scenario. You installed a package but Python cannot find it. What is a common cause

The virtual environment is not activated, or the package was installed into a different environment.

What is Ollama used for in this course

Running an LLM locally on your own machine so you can experiment without sending data to a hosted API.

What is a good habit before running a new tool you found online

Read what it does, confirm the source, and run it in a controlled folder or environment rather than your main system.

Artefact and reflection

Artefact

A working project folder with a virtual environment.

Reflection

Where in your work would install python and confirm it runs from the terminal. change a decision, and what evidence would make you trust that change?

Optional practice

Create one folder for your work and keep the environment inside it.