Getting Started· 15 min

macOS / Linux Setup

What you'll learn
  • Install or verify Python 3.10+ on macOS / Linux
  • Create and activate a .venv per session folder
  • Install dependencies and create your .env file
  • Run the first exercise end-to-end from the terminal

macOS and most Linux distributions ship with a built-in terminal and Python. You only need to make sure the Python version is recent enough and then create a virtual environment per session folder.

Which shell?
macOS uses zsh by default; Ubuntu/Debian uses bash. The commands below work identically in both.

1. Check your Python version

$ python3 --version

You need Python 3.10 or newer (3.12+ recommended for Session 6). If the version is too old or you get "command not found", install Python first.

macOS — install Python with Homebrew

If you do not have Homebrew yet:

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

Ubuntu / Debian — install Python with apt

$ sudo apt update && sudo apt install -y python3 python3-venv python3-pip

Fedora / RHEL — install Python with dnf

$ sudo dnf install -y python3 python3-virtualenv python3-pip

2. Open a terminal in the course folder

Navigate to the session folder you want to work on. Each session has its own requirements and .env, so always cd into the session first.

$ cd ~/Documents/AICourse/Session1

3. Create a virtual environment

$ python3 -m venv .venv

This creates a .venv/ folder inside the session — a private copy of Python where we will install the dependencies. It never touches your system Python.

4. Activate the virtual environment

$ source .venv/bin/activate
How to tell it worked
Your terminal prompt gets a (.venv) prefix. Run "which python" — it should point inside the .venv folder, not /usr/bin.
Every new terminal needs activation
If you close the terminal and open a new one, you must run "source .venv/bin/activate" again. VS Code does this automatically once you select the interpreter (see the VS Code Setup page).

5. Install the session dependencies

$ pip install -r requirements.txt

This installs openai, python-dotenv, and any other libraries the session needs. Repeat this step once per session folder, because each one has its own requirements.txt.

6. Create your .env file

$ cp .env.example .env

Open .env in your editor and paste your OpenAI API key (plus Anthropic and Google keys before Session 6). On macOS you can use any editor — here are a few ways:

  • code .env — open in VS Code (recommended)
  • nano .env — open in the built-in terminal editor
  • open -e .env — open in TextEdit (macOS only)
.env
OPENAI_API_KEY=sk-...your-key-here...
# Session 6 only
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...

# Optional overrides
OPENAI_MODEL=gpt-4o-mini

7. Run your first script

$ python src/01_text_basic.py --prompt "hello"

If you see a response from the model, everything is wired up correctly. You are ready for Session 1.

Handy commands to remember

Cheat sheet
# Activate venv
source .venv/bin/activate

# Deactivate when done
deactivate

# See which Python is active
which python

# See installed packages
pip list

# Upgrade pip itself
python -m pip install --upgrade pip

# Run a script from the session folder
python src/01_text_basic.py --prompt "..."

Common problems

"python: command not found"
On macOS/Linux use python3 and pip3 (not python/pip) unless you explicitly alias them. Inside an activated .venv both names work.
"ModuleNotFoundError: No module named 'openai'"
Your .venv is not activated or you installed requirements into the system Python. Run "source .venv/bin/activate" then "pip install -r requirements.txt" again.
"OPENAI_API_KEY is missing"
Check that .env exists in the same folder you are running from, that the key has no quotes, and that you saved the file.
Linux: "ensurepip is not available"
On Debian/Ubuntu install python3-venv explicitly: sudo apt install python3-venv
You are ready
Setup is done. Head to Session 1 from the sidebar — or read the VS Code Setup page next if you want a proper editor.