Dev Environment Setup
Before writing any code, you need three things working: VS Code as your editor, Jupyter notebooks for interactive development, and the Anthropic Python SDK connected to a valid API key. This module gets all three running and ends with a verified "Hello Claude" test.
1. What You'll Need
- Python 3.9 or later, check with
python --versionorpython3 --version - VS Code, download from
code.visualstudio.com - An Anthropic API key, obtained from
console.anthropic.com - ~10 minutes and a terminal
2. Install VS Code Extensions
Open VS Code and install these two extensions from the Extensions panel (Ctrl+Shift+X / Cmd+Shift+X):
- Python, publisher: ms-python. Enables Python language support, linting, and virtual environment detection.
- Jupyter, publisher: ms-toolsai. Lets you run
.ipynbnotebooks directly inside VS Code without launching a browser.
3. Create Your Project Folder
Pick a home for your lab files. All advanced modules will build on the same notebook, so one folder is all you need.
mkdir claude-architect-lab
cd claude-architect-lab
4. Set Up a Virtual Environment
A virtual environment keeps the SDK and its dependencies isolated from the rest of your system, important when you're working with multiple Python projects.
# Create the environment
python -m venv .venv
# Activate it
# macOS / Linux:
source .venv/bin/activate
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Windows (Command Prompt):
.venv\Scripts\activate.bat
Your terminal prompt should now show (.venv) to confirm it's active.
5. Install Dependencies
pip install anthropic python-dotenv ipykernel
- anthropic, the official Python SDK for the Claude API
- python-dotenv, loads your
.envfile so the API key is never hardcoded - ipykernel, registers your virtual environment as a Jupyter kernel so VS Code can find it
6. Get Your API Key
- Go to
console.anthropic.comand sign in (or create a free account). - Navigate to API Keys in the left sidebar.
- Click Create Key, give it a name like "architect-lab", and copy the key, it starts with
sk-ant-.
You only see the full key once, so copy it immediately.
7. Store Your Key Safely
Create two files in your project folder:
ANTHROPIC_API_KEY=sk-ant-api03-YOUR-KEY-HERE
.env
.venv/
__pycache__/
*.pyc
.ipynb_checkpoints/
.gitignore above ensures .env stays local. If you accidentally push a key, rotate it immediately in the Anthropic console, old keys can be used by anyone who finds them in your git history.
8. Create Your Lab Notebook
- Open your project folder in VS Code:
File → Open Folder - Create a new file named
lab.ipynb(File → New File, then save with the.ipynbextension). - VS Code will open it as a notebook. In the top-right corner, click Select Kernel.
- Choose Python Environments → select the
.venvyou just created. If it doesn't appear, runPython: Select Interpreterfrom the command palette first.
9. Hello Claude, Your First Cell
Add a new code cell and paste the following. Run it with Shift+Enter.
import anthropic
from dotenv import load_dotenv
load_dotenv() # reads ANTHROPIC_API_KEY from your .env file
client = anthropic.Anthropic()
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=256,
messages=[
{"role": "user", "content": "In one sentence, what is the Claude API?"}
]
)
print(message.content[0].text)
If everything is configured correctly, you should see a one-sentence response from Claude. That's your environment confirmed.
10. Understanding the Response Object
Before moving to Module 1, it's worth knowing what the API returned. Add a second cell:
print("Stop reason:", message.stop_reason)
print("Input tokens:", message.usage.input_tokens)
print("Output tokens:", message.usage.output_tokens)
print("Model:", message.model)
- stop_reason,
"end_turn"means Claude finished naturally. The exam tests this heavily. - usage, input and output token counts used to calculate cost.
- model, confirms which model version actually ran your request.
lab.ipynb. A well-structured notebook with clear headings and focused cells is also good practice for the structured output modules later in the lab.
Troubleshooting
| Problem | Most likely cause | Fix |
|---|---|---|
AuthenticationError | .env not found or key is wrong | Check the file is in the project root, not a subfolder. Confirm no extra spaces around the =. |
| Kernel not listed | .venv not registered with Jupyter | Run python -m ipykernel install --user --name .venv inside your activated environment. |
ModuleNotFoundError: anthropic | Wrong Python environment active | Confirm (.venv) is in your terminal prompt, then re-run pip install anthropic. |
| VS Code shows "No kernel" | Jupyter extension not installed | Install the Jupyter extension from the Extensions panel and reload VS Code. |
Lab Exercise: Environment Verification & Response Anatomy
Self-driven lab Module0_Self_Driven_Lab.ipynbObjective: build a clean local notebook workspace and verify that Claude requests run through the configured API key.
- Create or verify the project folder, virtual environment, `.env`, and Jupyter kernel setup.
- Run a minimal Claude request and print the returned text, model name, token usage, and stop reason.
- Intentionally break one setup assumption, such as a missing key or wrong kernel, then document the error and fix.
- Record the environment checklist you would hand to a teammate before starting the agent labs.
A working notebook environment plus a short troubleshooting checklist.