Environments & Packaging Basics
10 examples to get you started with Environments and Packaging - 7 basic and 3 intermediate.
Search across all documentation pages
10 examples to get you started with Environments and Packaging - 7 basic and 3 intermediate.
python3 --version)curl -LsSf https://astral.sh/uv/install.sh | shpyproject.toml (create one with uv init if needed)A virtual environment isolates project dependencies from the system Python.
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
which python # points inside .venvvenv ships with Python 3.14 - no extra install required.venv/bin to PATH so pip and python are project-localdeactivate when switching projects.venv/ - add it to .gitignoreRelated: uv - The Fast Toolchain - faster alternative to manual venv + pip
Install dependencies into the active environment.
pip install httpx
pip freeze > requirements.txtpip resolves and installs from PyPI into the active venv onlypip freeze captures exact versions for reproducibilitypyproject.toml + lockfiles for new projects (see pyproject.toml Explained)pip install -r requirements.txt to restore a frozen setuv replaces venv + pip + pip-tools in one fast tool.
uv init myapp
cd myapp
uv add httpx pydantic
uv run python -c "import httpx; print(httpx.__version__)"uv init creates pyproject.toml and a .venv automaticallyuv add writes dependencies to pyproject.toml and updates the lockfileuv run executes inside the project environment without manual activationRelated: uv - The Fast Toolchain - full uv workflow
Modern projects declare metadata and dependencies in one file.
[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = [
"httpx>=0.28",
"pydantic>=2",
][project] is the PEP 621 metadata block every build tool readsrequires-python prevents installs on unsupported interpreters>=) balance flexibility with reproducibility via lockfiles[tool.*]Related: pyproject.toml Explained - every section decoded
Lockfiles record exact resolved versions for reproducible installs.
uv lock
uv syncuv lock resolves all dependencies and writes uv.lockuv sync installs exactly what the lockfile specifiesuv lock when you change pyproject.toml dependenciesRelated: Dependency Resolution & Lockfiles - pinning strategies
Test against several Python versions on one machine.
uv python install 3.13 3.14
uv venv --python 3.14
uv run --python 3.13 pytestuv python install downloads interpreters without pyenv--pythonuv run --pythonrequires-python in pyproject.toml to your lowest supported versionRelated: Managing Python Versions - pyenv and CI matrices
Edit source code and see changes without reinstalling.
uv pip install -e .
# or: pip install -e .-e (editable) links the package into the venv via a .pth filesrc/myapp/ take effect on the next importsrc/ layout so tests import the installed package, not the repo rootRelated: Editable Installs & Local Packages - src layout and monorepos
Separate runtime and development dependencies.
[project]
dependencies = ["fastapi>=0.115"]
[dependency-groups]
dev = ["pytest>=8", "ruff>=0.9", "mypy>=1.14"]uv sync --group dev
uv sync --no-dev # production install only[dependency-groups] (PEP 735) replaces ad-hoc requirements-dev.txtuv sync --group dev installs runtime + dev toolsPull packages from an internal mirror or private PyPI.
export UV_INDEX_URL=https://pypi.internal.corp/simple/
uv sync# pyproject.toml alternative
[[tool.uv.index]]
url = "https://pypi.internal.corp/simple/"
default = true~/.netrc, env vars, or CI secrets - never in pyproject.toml--index-url overrides the default for a single commandRelated: Private Indexes & Mirrors - auth and CI setup
Clone, install, and run in three commands.
git clone https://github.com/org/myapp.git && cd myapp
uv sync --frozen
uv run pytest--frozen fails if the lockfile is out of date with pyproject.tomluv sync --frozen commandRelated: Environments Best Practices - team conventions
Stack versions: This page was written for Python 3.14.0, FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.
Reviewed by Chris St. John·Last updated Jul 19, 2026