Skip to content

Installing from requirements.txt with uv

Problem: Installing multiple packages from requirements.txt

When using uv—a modern Python package manager designed for speed—you naturally want to leverage your existing requirements.txt files. Manually installing each dependency becomes impractical when you're dealing with:

  • Large projects with extensive dependency lists
  • Team environments where dependencies are shared via requirements.txt
  • Automated workflows using standardized Python dependency files
  • Projects transitioning from pip to uv

The challenge is to achieve efficient dependency installation while maintaining compatibility with your existing toolchain.

Solution: Basic installations and project workflows

For installing dependencies from requirements.txt, uv provides both simple one-time installation and project-integrated approaches.

Option 1: Install directly into environment

Use this command for straightforward installation into your active environment:

bash
uv pip install -r requirements.txt

How this works:

  1. Uses uv's compatible pip implementation
  2. Processes packages sequentially with dependency resolution
  3. Supports all standard requirements.txt syntax including version specifiers

Option 2: Add requirements to project configuration

When working in a project directory (for application/library development):

bash
uv add -r requirements.txt

Key advantages of this approach:

  1. Installs dependencies into current environment
  2. Automatically adds them to your pyproject.toml
  3. Creates pyproject.toml if missing
  4. Preserves dependency versions with pinned constraints

Additional options for advanced workflows

Include these flags for specific use cases:

  • Dry run (validate before installing):

    bash
    uv pip install -r requirements.txt -n
  • Install only direct dependencies:

    bash
    uv pip install -r requirements.txt --no-deps
  • Upgrade existing packages:

    bash
    uv pip install -r requirements.txt --upgrade

Key differences between installation methods

MethodBest ForModifies ProjectPersistent Config
uv pip installTemporary environments, CI pipelines
uv addApplication development, team projects✅ (pyproject.toml)

Best practices

  1. Always run from your project root directory
  2. Create environments with uv venv first:
    bash
    uv venv .venv && source .venv/bin/activate
  3. For existing pipelines, simply replace pip install -r requirements.txt with uv pip install -r requirements.txt
  4. Use uv add for new projects to leverage pyproject.toml benefits

Performance Note

uv typically installs dependencies 10-100x faster than pip, making it especially beneficial for large requirements files.

Compatibility

While uv supports most pip syntax, ensure your requirements.txt doesn't contain obscure flags unavailable in uv. Test complex requirements with uv pip install --dry-run.

Migrating projects to uv

For established projects using requirements.txt but wanting to transition to pyproject.toml:

bash
# Convert your requirements.txt to pyproject.toml
uv add -r requirements.txt

# Future installations use pyproject.toml
uv install

This approach preserves dependency versions while moving your project to modern packaging standards.