Python venv Project Setup Cheat Sheet

Project-level setup patterns for Python virtual environments, pyproject.toml, editable installs, dev tools, and team onboarding.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Project bootstrap
Create project and venv
mkdir myapp && cd myapp && python -m venv .venv

# Create a project folder and initialize a virtual environment.

Ignore the local venv in Git
.venv/
venv/
__pycache__/
*.pyc

# Add the environment directory to .gitignore.

Install common local tooling
python -m pip install black ruff pytest

# Install formatter, linter, and test tooling in the venv.

## pyproject.toml patterns
Minimal pyproject.toml example
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "myapp"
version = "0.1.0"
dependencies = [
  "requests>=2.31",
]

# Basic modern packaging metadata for a local project.

Install project editable from pyproject
python -m pip install -e .

# Install the current project into the venv in editable mode.

Install editable with dev extras
python -m pip install -e ".[dev,test]"

# Install project plus optional development dependencies.

## Team onboarding and automation
Typical README quick-start block
```bash
python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip setuptools wheel
python -m pip install -r requirements.txt
```

# Copy-paste setup commands for local onboarding.

Makefile setup target
setup:
  python -m venv .venv
  . .venv/bin/activate && python -m pip install -U pip setuptools wheel
  . .venv/bin/activate && python -m pip install -r requirements.txt

# Automate local environment setup for contributors.

Auto-activate with direnv + layout python
layout python python3

# Example .envrc for shells that use direnv.

Recommended next

No recommendations yet.