74 lines
1.8 KiB
Markdown
74 lines
1.8 KiB
Markdown
# 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
|
|
```bash
|
|
# 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
|
|
```bash
|
|
# 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
|
|
```bash
|
|
# Initialize new project
|
|
uv init
|
|
|
|
# Add dependencies
|
|
uv add fastapi uvicorn
|
|
|
|
# Remove dependencies
|
|
uv remove package_name
|
|
|
|
# Sync dependencies
|
|
uv sync
|
|
```
|
|
|
|
### Running Commands
|
|
```bash
|
|
# 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` |