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
touv
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:
uv pip install -r requirements.txt
How this works:
- Uses
uv
's compatiblepip
implementation - Processes packages sequentially with dependency resolution
- 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):
uv add -r requirements.txt
Key advantages of this approach:
- Installs dependencies into current environment
- Automatically adds them to your
pyproject.toml
- Creates
pyproject.toml
if missing - Preserves dependency versions with pinned constraints
Additional options for advanced workflows
Include these flags for specific use cases:
Dry run (validate before installing):
bashuv pip install -r requirements.txt -n
Install only direct dependencies:
bashuv pip install -r requirements.txt --no-deps
Upgrade existing packages:
bashuv pip install -r requirements.txt --upgrade
Key differences between installation methods
Method | Best For | Modifies Project | Persistent Config |
---|---|---|---|
uv pip install | Temporary environments, CI pipelines | ❌ | ❌ |
uv add | Application development, team projects | ✅ (pyproject.toml ) | ✅ |
Best practices
- Always run from your project root directory
- Create environments with
uv venv
first:bashuv venv .venv && source .venv/bin/activate
- For existing pipelines, simply replace
pip install -r requirements.txt
withuv pip install -r requirements.txt
- Use
uv add
for new projects to leveragepyproject.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
:
# 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.