Setting Up the Development Environment

Before writing a single line of agent code, the development environment needs to be set up correctly. This topic walks through everything required — from installing Python to configuring API keys — so that coding can begin without any setup hurdles.

What Will Be Installed

  • Python 3.10 or higher
  • A code editor (VS Code recommended)
  • pip (Python package manager)
  • Virtual environment
  • OpenAI Python SDK
  • LangChain (used in later topics)
  • Environment variable management (python-dotenv)

Step 1 — Install Python

Python is the primary language used for building AI Agents in this course.

Check if Python is Already Installed

python --version
# or
python3 --version

If the version shown is 3.10 or higher, proceed to Step 2. Otherwise, download Python from the official website: https://www.python.org/downloads/

Installation Tips

Operating SystemRecommended Method
WindowsDownload .exe installer from python.org — check "Add to PATH" during install
macOSUse Homebrew: brew install python
Linux (Ubuntu)sudo apt update && sudo apt install python3 python3-pip

Step 2 — Install VS Code (Code Editor)

VS Code is a free, lightweight code editor with excellent Python support. Download it from: https://code.visualstudio.com/

Recommended VS Code Extensions

  • Python — by Microsoft (essential)
  • Pylance — for code intelligence and autocomplete
  • GitLens — for version control
  • REST Client — for testing API calls

Step 3 — Create a Project Folder

# Create a new project directory
mkdir ai-agents-course
cd ai-agents-course

All agent code for this course will live inside this folder.

Step 4 — Set Up a Virtual Environment

A virtual environment isolates the project's Python packages from other projects. This prevents version conflicts between different projects.

# Create virtual environment
python -m venv venv

# Activate it

# On Windows:
venv\Scripts\activate

# On macOS/Linux:
source venv/bin/activate

# Confirm activation (terminal shows the venv name)
(venv) $

The (venv) prefix in the terminal confirms the virtual environment is active. All packages installed now will only be available in this project.

Step 5 — Install Core Packages

# Upgrade pip first
pip install --upgrade pip

# Install OpenAI SDK
pip install openai

# Install LangChain (for later topics)
pip install langchain langchain-openai

# Install dotenv for managing API keys
pip install python-dotenv

# Install requests for making HTTP calls
pip install requests

Verify Installation

python -c "import openai; print('OpenAI SDK version:', openai.__version__)"
python -c "import langchain; print('LangChain version:', langchain.__version__)"

Step 6 — Get an OpenAI API Key

The OpenAI API is required to access GPT-4o and other models used throughout this course.

How to Get the API Key

  1. Go to https://platform.openai.com/
  2. Create a free account (or log in)
  3. Click on API Keys in the left menu
  4. Click Create new secret key
  5. Copy the key — it will only be shown once

Important: Never share the API key publicly. Never commit it to GitHub. Never paste it directly into code files.

Step 7 — Store the API Key Safely with .env

Create a .env file in the project root to store sensitive keys:

# .env file (DO NOT commit to GitHub)
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Add .env to .gitignore so it is never accidentally committed:

# .gitignore
.env
venv/
__pycache__/
*.pyc

Load the key in Python code using python-dotenv:

import os
from dotenv import load_dotenv

load_dotenv()  # Loads variables from .env file

api_key = os.getenv("OPENAI_API_KEY")
print("API Key loaded:", "Yes" if api_key else "No")

Step 8 — Test the Setup with a Simple API Call

Create a file named test_setup.py and run it to confirm everything is working:

# test_setup.py
import os
from dotenv import load_dotenv
import openai

load_dotenv()

client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user",   "content": "Say 'Setup is working!' in exactly 3 words."}
    ]
)

print(response.choices[0].message.content)
# Run the test
python test_setup.py

# Expected output:
Setup is working!

If this works, the environment is ready.

Recommended Project Structure

ai-agents-course/
│
├── .env                 ← API keys (never commit)
├── .gitignore           ← Files to ignore in Git
├── requirements.txt     ← List of all packages
│
├── 01_basics/
│   ├── test_setup.py
│   └── first_agent.py
│
├── 02_tools/
│   ├── weather_tool.py
│   └── search_tool.py
│
├── 03_memory/
│   ├── memory_manager.py
│   └── agent_with_memory.py
│
├── 04_advanced/
│   ├── react_agent.py
│   └── multi_agent.py
│
└── utils/
    ├── helpers.py
    └── config.py

Save Dependencies to requirements.txt

Once all packages are installed, save them to a file so the environment can be recreated later:

pip freeze > requirements.txt

To recreate the environment on a different machine:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Troubleshooting Common Setup Issues

IssueFix
python command not foundTry python3 instead; or reinstall Python and check "Add to PATH"
API key error: 401 UnauthorizedCheck the key is correct; confirm .env is loaded with load_dotenv()
ModuleNotFoundError: No module named 'openai'Run pip install openai inside the activated virtual environment
Rate limit error from OpenAIAdd a small delay between API calls; check billing at platform.openai.com
VS Code not finding the venv PythonPress Ctrl+Shift+P → "Python: Select Interpreter" → choose the venv Python

Summary

The development environment is now fully configured with Python, VS Code, a virtual environment, the OpenAI SDK, LangChain, and a secure API key setup using .env. The project structure has been defined to keep code organised as the course progresses. With this foundation in place, building the first real AI Agent can begin in the very next topic.

Leave a Comment

Your email address will not be published. Required fields are marked *