Chapter 07
Environment
Environment
Video: Watch this lesson
For this module, all you need is Python with Jupyter.
Prerequisites
You need the following:
- Python (3.14 or later)
- An OpenAI account (or an OpenAI-compatible provider like Groq, Gemini, or Ollama)
- Basic familiarity with Python and the command line
Creating the project
We'll start from scratch with no cloning needed - you'll create the project yourself, step by step, either locally or on GitHub Codespaces.
Creating the project locally
First, install uv - it's a Python package manager, and I switched all my projects to it because it's fast and convenient. Once I started using it, I never wanted to go back.
On Mac or Linux:
curl -LsSf https://astral.sh/uv/install.sh | shOn Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"(You can also use pip install uv if you prefer.)
Create an empty folder for the project and initialize it:
mkdir llm-zoomcamp-2026-code
cd llm-zoomcamp-2026-code
uv initThis creates a pyproject.toml and a basic project structure.
Creating the project on GitHub Codespaces
We suggest using Codespaces because everyone gets the same Ubuntu, Python, and Docker. That makes it easier to help each other when problems come up.
Setup:
- Create a new repo on GitHub. Name it whatever you want, for example
llm-zoomcamp-2026-codeorintroduction-to-rag, and add a README. - Open the repo, click the green
<> Codebutton, switch to the Codespaces tab, and create a codespace.
You now have a remote environment running in Codespaces. By default it
opens an in-browser editor, but you can connect VS Code on your desktop
for a better experience. Click Codespaces in the bottom-left corner and
pick "Open in Visual Studio Code Desktop" from the dropdown.
Once VS Code opens, press ctrl+` to bring up the terminal and
initialize the project the same way as locally:
pip install uv
uv initAdding dependencies
Now add the dependencies we'll need:
uv add requests minsearch openai jupyter python-dotenvThis installs:
requests- to fetch the FAQ dataset from the internetminsearch- a simple in-memory search engine for indexing and searching textopenai- the OpenAI API client for calling the LLMjupyter- the notebook environment where we'll write and run codepython-dotenv- to load API keys from a.envfile
Setting up API keys
We need an API key to talk to the LLM. If you're using OpenAI, you'll need to deposit some money first. The minimum is 5 goes a long way.
I also recommend creating a separate OpenAI project for the course. Then you can open the usage page and see exactly how much you spent here, apart from your other work.
The safest way to store the key is in a .env file that never gets
committed to git.
Create a .env file in your project folder and put your API key in
it:
OPENAI_API_KEY=sk-YOUR_KEY_HERENow add .env to .gitignore to make sure you never accidentally
commit your key:
.envNever commit .env to git. Treat the API key like a password. If it
leaks, someone else can run up charges on your account.
Starting Jupyter
Start Jupyter:
uv run jupyter notebookCreate a new notebook. Throughout the course, you'll copy code from the section notes into notebook cells.
Check that the OpenAI client works:
from dotenv import load_dotenv
load_dotenv()
from openai import OpenAI
openai_client = OpenAI()If you see an error, make sure the key in your .env file is
correct.
For Groq or other OpenAI-compatible providers, add the key to
.env:
GROQ_API_KEY=your_key_hereAnd configure the client:
from openai import OpenAI
import os
openai_client = OpenAI(
api_key=os.getenv("GROQ_API_KEY"),
base_url="https://api.groq.com/openai/v1"
)(Optional) Auto-loading .env with dirdotenv
If you don't want to call load_dotenv() in every notebook, use
dirdotenv.
It loads .env files automatically when you cd into a directory:
uv tool install dirdotenv
echo 'eval "$(dirdotenv hook bash)"' >> ~/.bashrcRestart your terminal, and now whenever you enter the project
directory, the variables from .env are loaded automatically. No
load_dotenv() needed.
