Some text some message..
Back Add Dependencies using the UV Package Manager 17 Jun, 2025

To add dependencies using the UV Package Manager, you can use it similarly to how you'd use pip, but faster and more efficiently. Here's how:


Step-by-Step: Adding Dependencies with UV

1. Install a package (like pip)

uv pip install <package-name>

Example:

uv pip install numpy pandas

This installs numpy and pandas into your environment.


2. Create a requirements.txt or pyproject.toml (optional but recommended)

If you're managing a project, it's good practice to declare dependencies in one of these files.


3. Compile a lock file for reproducibility

uv pip compile requirements.in

This generates a requirements.lock file that freezes exact versions.


4. Install from a lock file (like pip-sync)

uv pip sync requirements.lock

Ensures your environment exactly matches the locked versions.


5. Using with pyproject.toml (for modern Python projects)

If you're using a pyproject.toml, you can let UV handle dependencies via standard PEP 621 configuration.


🔄 Example Workflow

# Step 1: Create a virtual environment
uv venv

# Step 2: Activate the environment
source .venv/bin/activate   # (Linux/macOS)
.venv\Scripts\activate      # (Windows)

# Step 3: Add dependencies
uv pip install fastapi uvicorn

# Step 4: (Optional) Freeze versions into a lock file
uv pip compile requirements.in

# Step 5: Reinstall in new environments
uv pip sync requirements.lock