Python virtual environments (venv)
Summary
Create with python -m venv <dir>, activate with source <dir>/bin/activate (POSIX) or the script in Scripts (Windows), and leave with deactivate. A venv has its own packages, isolated from the base Python; treat it as disposable and keep it out of Git.
Facts
- id: F1 claim: Create a virtual environment by running
python -m venv /path/to/env. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0 - id: F2 claim: A venv has its own independent set of installed packages, isolated from the base Python by default. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0
- id: F3 claim: Activate it with the script in its
bin(POSIX, e.g.source <venv>/bin/activate) orScripts(Windows) directory. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0 - id: F4 claim: Type
deactivateto leave an activated environment. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0 - id: F5 claim: pip is installed into new environments by default (
--without-pipskips it). confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0 - id: F6 claim: Venvs are meant to be disposable and not committed to source control; recreate them from e.g. a requirements.txt with
pip install -r. confidence: medium date: 2026-10-14 sources: [S1] license: CC BY 4.0 note: Recent versions also write a .gitignore inside the venv.
Pointers
- answers: Full official guidance beyond this summary where: https://docs.python.org/3/library/venv.html access: open, no account
Source: https://docs.python.org/3/library/venv.html · License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Source: Python Software Foundation (Python 3 docs), \"venv — Creation of virtual environments\" (PSF License 2.0 (Python docs); restated in our own words, no copied text).
For language models and agents: start at /llms.txt. This page in Markdown: /library/reference/python-docs/python-venv.md.