Virtual environments, pip, and project structure
Words made simple
A few useful meanings before you read the explanation.
- Virtual environment
- A separate Python package environment for a project, helping its dependencies stay independent from other projects.
- AI
- Software techniques for tasks such as recognizing patterns, understanding language or generating content.
- API
- A way for one piece of software to ask another for data or an action. A claims API might return the current status of a claim.
More words from this lesson
- Schema
- A description of the fields and value types that data should contain. It helps check that an answer has the expected shape.
- Dependency
- A library or package that your application relies on. Compatible versions help the application run as expected.
- Pydantic
- A Python library for describing data fields and checking or converting incoming values against those descriptions.
- FastAPI
- A Python framework for building APIs, often used with typed request and response data.
Overview
- A virtual environment isolates a project's Python packages.
pipinstalls packages into the selected environment.- Project structure separates API routes, business services, adapters, and tests so the AI code does not become one notebook-sized script.
Why this matters
AI libraries frequently require specific versions, and conflicts between projects can break environments.
An everyday example
Different kitchens keep their own ingredients and recipe versions.
A technical example
For a future Python project: python -m venv .venv, activate it, then python -m pip install fastapi pydantic httpx.
How it works
- Create environment
- Select interpreter
- Install pinned compatible packages
- Record dependencies
- Reproduce in CI and a container.
Architecture and flow
Dependency specification → isolated environment → application → reproducible deployment.
The insurance assistant example
The insurer's parsing worker has document/OCR packages; its Node API does not inherit those heavy dependencies.
When to use it
Every independently deployed Python application.
When to avoid it
Do not install arbitrary packages globally or rely on packages left over from a personal notebook session.
Interview answer
“I isolate Python dependencies, pin compatible versions, and structure services around contracts so experiments can become reproducible deployments.”
Benefits, trade-offs, and production considerations
- A conceptual layout is
app/api,app/services,app/adapters,app/schemas, andtests, configured throughpyproject.toml. - This is a future-project example; no such folders are created by these notes.
- Scan dependencies and never commit API keys into environment files.
Can you explain it without the notes?
Virtual environments, pip, and project structure
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
A virtual environment isolates a project's Python packages. pip installs packages into the selected environment. Project structure separates API routes, business services, adapters, and tests so the AI code does not become one notebook-sized script.
Turn this concept into a clear answer.
Practice this conceptAdapted from 13_AI.MD · “Virtual environments, pip, and project structure”. Examples are study fragments; framework behavior can depend on your version.