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:
uv pip install <package-name>
Example:
uv pip install numpy pandas
This installs numpy and pandas into your environment.
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.
uv pip compile requirements.in
This generates a
requirements.lockfile that freezes exact versions.
uv pip sync requirements.lock
Ensures your environment exactly matches the locked versions.
pyproject.toml (for modern Python projects)If you're using a pyproject.toml, you can let UV handle dependencies via standard PEP 621 configuration.
# 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