You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
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.
A well-configured development environment prevents the most common frustrations new AI developers face:
Most AI libraries and SDKs have first-class Python support. We recommend Python 3.10+ for compatibility with modern AI tooling.
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
Always use a virtual environment for each project. This isolates dependencies and prevents conflicts.
# 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
pip install poetry
poetry init
poetry add openai anthropic
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 |
pip install openai anthropic
import openai
import anthropic
print(f"OpenAI SDK version: {openai.__version__}")
print(f"Anthropic SDK version: {anthropic.__version__}")
API keys are secrets that authenticate your requests. Never commit them to source control.
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.
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
openai>=1.0.0
anthropic>=0.18.0
python-dotenv>=1.0.0
tiktoken>=0.5.0
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.
venv or Poetry).pip install openai anthropic..env file — never in code.