Files
quixotic/.serena/memories/uv_usage_guide.md
Andrey Kondratev d4debf9b63 python
2025-09-09 15:39:28 +05:00

1.8 KiB

UV Package Manager Usage Guide

Overview

UV is a fast Python package manager and project management tool, designed as a drop-in replacement for pip and virtualenv.

Key Commands Used

Package Installation

# Install packages from requirements.txt
uv pip install -r requirements.txt

# Install specific packages
uv pip install fastapi uvicorn aiofiles pydantic

# Install with specific Python version
uv pip install --python 3.13 package_name

Environment Management

# Create virtual environment
uv venv

# Create with specific Python version
uv venv --python 3.13

# Activate environment (still use standard activation)
source .venv/bin/activate  # Linux/Mac
.venv\Scripts\activate     # Windows

Project Management

# Initialize new project
uv init

# Add dependencies
uv add fastapi uvicorn

# Remove dependencies
uv remove package_name

# Sync dependencies
uv sync

Running Commands

# Run Python with uv environment
uv run python script.py

# Run with specific requirements
uv run --with requests python script.py

Advantages Over Pip

  • Much faster installation and dependency resolution
  • Better dependency conflict resolution
  • Built-in virtual environment management
  • Lockfile support for reproducible builds
  • Cross-platform compatibility

Usage in This Project

  • Used uv pip install to install FastAPI dependencies
  • Works with existing requirements.txt files
  • Automatically resolves and installs dependencies
  • Handles complex package builds (though some like psycopg2 may still have issues on certain Python versions)

Best Practices

  • Use uv pip install as drop-in replacement for pip install
  • Create virtual environments with uv venv
  • Use uv sync for consistent dependency management
  • Check version with uv --version