Virtual environments, pip, and project structure
Practice this questionOverview
- 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.