Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Virtual Environments

Direct answer

Virtual environments (python -m venv .venv) isolate a project's Python packages from the system and other projects, so each automation has the exact dependencies it needs.

When to use this

Use this when isolating Python dependencies.

First 30 seconds

1. Virtual environments isolate dependencies per project.

2. Never install into system Python.

3. Commit lock files, not the venv.

4. Recreate in CI.

5. uv/poetry as alternatives.

Operational verification

project → venv → isolated packages

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Python automation runtime
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPython automation runtime · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when isolating Python dependencies.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

The negative fixture should deliberately exercise risks such as environment drift, implicit coercion, broad exception handling, blocking/async confusion, shell quoting/subprocess risks, partial writes and non-deterministic external APIs, choosing the cases most relevant to venv interpreter/path identity, dependency isolation, activation-independent invocation and reproducible package/version lock for noninteractive runs.

Step 2 Example Narrow the fault
python3 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt
Step 3 Common mistakes Narrow the fault
  • Committing the .venv folder to Git.
  • Forgetting to activate it in cron/CI jobs.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • python -m venv .venv creates an isolated environment.
  • Activate before installing packages.
  • One venv per project.
Key checks
  • python3 -m venv .venv — create
  • . .venv/bin/activate && which python — active env
  • pip freeze > requirements.txt — capture deps
ReferenceWhy it matters1 section · depth on demand

What it is

A virtual environment is an isolated Python install per project, so dependency versions do not clash with the OS or other projects.

ReferenceImportant terms & boundaries2 sections · depth on demand

In depth

A virtual environment is an isolated Python installation for one project, with its own packages and versions. It prevents conflicts between projects and with the system Python, and makes dependencies explicit.

python3 -m venv .venv
source .venv/bin/activate            # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
which python                          # confirm the venv is active
deactivate

Do not commit .venv/ to Git — commit requirements.txt (or pyproject.toml with a lock file) instead. Tools such as uv or Poetry create and sync environments faster and record exact versions. In cron jobs and systemd units, call the venv's interpreter directly (/opt/tool/.venv/bin/python script.py), since activation scripts do not run there.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPython automation runtime current

Authoritative/upstream documentation reviewed for bounded claims in Python Automation > Virtual Environments. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://docs.python.org/3/library/venv.html · confidence 94%
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

For venv interpreter/path identity, dependency isolation, activation-independent invocation and reproducible package/version lock for noninteractive runs, prefer typed fields and stable IDs over human presentation text.

Confirmation

Confirm action

Continue?