You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Setting Up Your AI Development Environment
Setting Up Your AI Development Environment
Before you can build AI applications, you need a solid development environment. This lesson covers everything from Python setup and virtual environments to installing SDKs, managing API keys, and structuring your projects for success.
Why Environment Setup Matters
A well-configured development environment prevents the most common frustrations new AI developers face:
- Dependency conflicts between projects
- Leaked API keys that cost money or compromise security
- Inconsistent behaviour between your machine and production
- Wasted time debugging setup issues instead of building
Python Setup
Most AI libraries and SDKs have first-class Python support. We recommend Python 3.10+ for compatibility with modern AI tooling.
Checking Your Python Version
python3 --version
# Python 3.11.7 (or similar)
If you need to install or manage multiple Python versions, use pyenv:
# Install pyenv (macOS / Linux)
curl https://pyenv.run | bash
# Install a specific Python version
pyenv install 3.11.7
pyenv global 3.11.7
Virtual Environments
Always use a virtual environment for each project. This isolates dependencies and prevents conflicts.
Using venv (built-in)
# Create a virtual environment
python3 -m venv .venv
# Activate it
source .venv/bin/activate # macOS / Linux
.venv\Scripts\activate # Windows
# Verify
which python
# /path/to/project/.venv/bin/python
Using Poetry (alternative)
pip install poetry
poetry init
poetry add openai anthropic
Installing AI SDKs
The two most popular LLM providers have official Python SDKs:
| Provider | SDK Package | Install Command |
|---|---|---|
| OpenAI | openai |
pip install openai |
| Anthropic | anthropic |
pip install anthropic |
Quick Installation
pip install openai anthropic
Verifying Installation
import openai
import anthropic
print(f"OpenAI SDK version: {openai.__version__}")
print(f"Anthropic SDK version: {anthropic.__version__}")
API Keys
API keys are secrets that authenticate your requests. Never commit them to source control.
Getting Your API Keys
- OpenAI: Go to platform.openai.com/api-keys and create a new key
- Anthropic: Go to console.anthropic.com and generate a key
Environment Variables
Store keys in environment variables, not in your code:
# .env file (add to .gitignore!)
OPENAI_API_KEY=sk-proj-abc123...
ANTHROPIC_API_KEY=sk-ant-abc123...
Load them in Python using python-dotenv:
from dotenv import load_dotenv
import os
load_dotenv() # reads .env file
openai_key = os.getenv("OPENAI_API_KEY")
anthropic_key = os.getenv("ANTHROPIC_API_KEY")
Security tip: Add
.envto your.gitignoreimmediately after creating the file. If you accidentally commit a key, rotate it right away.
Project Structure
A clean project structure makes AI applications easier to maintain and extend:
my-ai-app/
├── .env # API keys (git-ignored)
├── .gitignore
├── requirements.txt # or pyproject.toml
├── src/
│ ├── __init__.py
│ ├── client.py # AI client setup
│ ├── prompts/
│ │ └── system.txt # Prompt templates
│ ├── tools/
│ │ └── search.py # Tool definitions
│ └── utils/
│ └── tokens.py # Token counting, etc.
├── tests/
│ └── test_client.py
└── README.md
requirements.txt Example
openai>=1.0.0
anthropic>=0.18.0
python-dotenv>=1.0.0
tiktoken>=0.5.0
Your First API Call
With everything set up, let's verify it works:
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI() # reads OPENAI_API_KEY automatically
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Say hello!"}
]
)
print(response.choices[0].message.content)
If you see a greeting in your terminal, your environment is ready.
Summary
- Use Python 3.10+ and manage versions with pyenv if needed.
- Always work inside a virtual environment (
venvor Poetry). - Install provider SDKs with
pip install openai anthropic. - Store API keys in environment variables via a
.envfile — never in code. - Structure your project with separate directories for source, prompts, tools, and tests.
- Verify your setup with a simple API call before building anything complex.