Install & Configure uv
This guide shows how to control the uv binary that Angreal uses for its virtual environment operations: letting Angreal install it automatically, installing it yourself, and pinning a specific version. For the rationale behind the binary-first, auto-install design, see the uv Integration Architecture explanation.
Automatic Installation
Section titled “Automatic Installation”UV is automatically installed when Angreal needs it, with no manual setup required.
When Installation Occurs
Section titled “When Installation Occurs”UV installation is triggered automatically when:
- First Virtual Environment Operation: Any
VirtualEnvclass usage - Module Import: When
angreal.integrations.venvis imported - Decorator Usage: When
@venv_requiredis applied to a function - Binary Not Found: When UV is not available in the system PATH
Installation Methods
Section titled “Installation Methods”Unix/macOS Installation
Section titled “Unix/macOS Installation”curl -LsSf https://astral.sh/uv/install.sh | shFeatures:
- Downloads latest stable UV release
- Installs to
~/.local/bin/(added to PATH) - Works on macOS and Linux distributions
- Uses secure HTTPS download
Windows Installation
Section titled “Windows Installation”irm https://astral.sh/uv/install.ps1 | iexFeatures:
- Downloads Windows-specific UV binary
- Installs to user-accessible location
- Automatically updates PATH environment variable
- Compatible with PowerShell 5.0+
Installation Verification
Section titled “Installation Verification”After installation, Angreal automatically verifies:
- Binary Availability: UV command is accessible via PATH
- Version Check: UV responds to
--versionflag - Functionality Test: Basic UV operations work correctly
Manual Installation
Section titled “Manual Installation”While automatic installation covers most cases, manual installation may be needed for:
- Corporate Networks: Restricted internet access
- Offline Environments: No external connectivity
- Custom Locations: Non-standard installation paths
- Specific Versions: Pinning to particular UV releases
Manual Installation Methods
Section titled “Manual Installation Methods”Via UV Installer (Recommended)
Section titled “Via UV Installer (Recommended)”# Unix/macOScurl -LsSf https://astral.sh/uv/install.sh | sh
# Windowsirm https://astral.sh/uv/install.ps1 | iexVia Package Managers
Section titled “Via Package Managers”Homebrew (macOS/Linux):
brew install uvScoop (Windows):
scoop install uvCargo (All Platforms):
cargo install uvVia Python (pip)
Section titled “Via Python (pip)”pip install uvNote: The pip installation may be slower than binary installations.
Configuration
Section titled “Configuration”Environment Variables
Section titled “Environment Variables”| Variable | Description | Default |
|---|---|---|
UV_INSTALL_DIR |
Custom installation directory | Platform default |
UV_NO_PROGRESS |
Disable progress bars | false |
UV_CACHE_DIR |
UV cache directory | Platform default |
Custom Installation Paths
Section titled “Custom Installation Paths”If UV is installed in a non-standard location, ensure it’s in your PATH:
# Add to your shell profile (.bashrc, .zshrc, etc.)export PATH="/custom/path/to/uv:$PATH"Troubleshooting
Section titled “Troubleshooting”Installation Failures
Section titled “Installation Failures”Network Issues
Section titled “Network Issues”RuntimeError: UV installation failedSolutions:
- Check internet connectivity
- Verify firewall/proxy settings allow HTTPS downloads
- Try manual installation
- Use alternative package managers
Permission Issues
Section titled “Permission Issues”Permission denied: Cannot install UVSolutions:
- Ensure write permissions to installation directory
- Install to user directory (default behavior)
- Use
sudofor system-wide installation (not recommended)
Path Issues
Section titled “Path Issues”UV binary not found after installationSolutions:
- Restart terminal/shell session
- Manually add UV location to PATH
- Verify installation directory is correct
Version Conflicts
Section titled “Version Conflicts”Multiple UV Installations
Section titled “Multiple UV Installations”If multiple UV installations exist:
from angreal.integrations.venv import VirtualEnv
# Check which UV version is being usedversion = VirtualEnv.version()print(f"Using UV version: {version}")Resolution:
- Use
which uv(Unix) orwhere uv(Windows) to find active binary - Remove conflicting installations
- Ensure desired UV binary is first in PATH
Outdated UV Version
Section titled “Outdated UV Version”Angreal works with any modern UV version, but newer versions offer better performance:
# Update UV manuallycurl -LsSf https://astral.sh/uv/install.sh | sh # Unix/macOSirm https://astral.sh/uv/install.ps1 | iex # WindowsPerformance Optimization
Section titled “Performance Optimization”Cache Configuration
Section titled “Cache Configuration”UV uses caching for optimal performance. Configure cache settings:
# Set custom cache directoryexport UV_CACHE_DIR="/path/to/large/disk/cache"
# Cache size will grow over time - monitor disk usagedu -sh $UV_CACHE_DIRNetwork Optimization
Section titled “Network Optimization”For faster package downloads:
# Use UV's built-in parallel downloads (default)# No configuration needed - UV automatically optimizes
# For corporate networks, configure proxy if neededexport HTTP_PROXY=http://proxy.company.com:8080export HTTPS_PROXY=http://proxy.company.com:8080Security Considerations
Section titled “Security Considerations”Download Security
Section titled “Download Security”- All UV downloads use HTTPS encryption
- Official installation scripts are cryptographically signed
- UV binaries are verified during installation
Subprocess Security
Section titled “Subprocess Security”- Angreal uses secure subprocess calls (no shell injection vulnerabilities)
- UV binary path is validated before execution
- All UV operations use proper argument arrays
Corporate Environments
Section titled “Corporate Environments”For enhanced security in corporate environments:
- Pre-install UV: Include in base system images
- Verify Checksums: Validate UV binary integrity
- Network Restrictions: Allow astral.sh domain for updates
- Audit Logs: Monitor UV operations if required
Integration Examples
Section titled “Integration Examples”Checking UV Status
Section titled “Checking UV Status”from angreal.integrations.venv import VirtualEnvfrom angreal import ensure_uv_installed, uv_version
def check_uv_status(): """Check UV installation and version.""" try: # Ensure UV is available ensure_uv_installed()
# Get version information version = uv_version() print(f"✅ UV is available: {version}")
# Test basic functionality pythons = VirtualEnv.discover_available_pythons() print(f"✅ UV discovered {len(pythons)} Python installations")
return True except Exception as e: print(f"❌ UV issue: {e}") return False
# Usageif check_uv_status(): print("UV is ready for use!")Custom Installation Logic
Section titled “Custom Installation Logic”import subprocessimport sysfrom pathlib import Path
def setup_uv_custom(): """Custom UV setup with error handling.""" uv_path = Path.home() / ".local" / "bin" / "uv"
if not uv_path.exists(): print("Installing UV...") try: if sys.platform == "win32": # Windows installation subprocess.run([ "powershell", "-Command", "irm https://astral.sh/uv/install.ps1 | iex" ], check=True) else: # Unix/macOS installation subprocess.run([ "bash", "-c", "curl -LsSf https://astral.sh/uv/install.sh | sh" ], check=True) print("✅ UV installed successfully") except subprocess.CalledProcessError: print("❌ UV installation failed") return False else: print("✅ UV already installed")
return True
# Usage in Angreal tasksimport angreal
@angreal.command(name="setup", about="Set up project with UV")def setup_project(): """Set up project ensuring UV is available.""" if setup_uv_custom(): # Proceed with UV-powered operations from angreal.integrations.venv import VirtualEnv venv = VirtualEnv(".venv", requirements="requirements.txt") print("✅ Project environment ready") else: print("❌ Setup failed - UV not available") sys.exit(1)Monitoring and Maintenance
Section titled “Monitoring and Maintenance”Health Checks
Section titled “Health Checks”Include UV health checks in your project setup:
import angrealfrom angreal.integrations.venv import VirtualEnv
@angreal.command(name="health", about="Check system health")def health_check(): """Comprehensive system health check.""" checks = []
# UV availability try: version = VirtualEnv.version() checks.append(f"✅ UV: {version}") except Exception as e: checks.append(f"❌ UV: {e}")
# Python discovery try: pythons = VirtualEnv.discover_available_pythons() checks.append(f"✅ Python versions: {len(pythons)} found") except Exception as e: checks.append(f"❌ Python discovery: {e}")
# Environment creation test try: test_env = VirtualEnv("health-test", now=False) if not test_env.exists: test_env = VirtualEnv("health-test") test_env.install("requests") # Test package installation checks.append("✅ Environment operations: Working") except Exception as e: checks.append(f"❌ Environment operations: {e}")
# Print results print("System Health Check:") for check in checks: print(f" {check}")Updates and Maintenance
Section titled “Updates and Maintenance”UV updates automatically when using the installation scripts. For maintenance:
# Check current versionuv --version
# Update to latest versioncurl -LsSf https://astral.sh/uv/install.sh | sh # Unix/macOSirm https://astral.sh/uv/install.ps1 | iex # Windows
# Clean UV cache if needed (saves disk space)uv cache cleanFurther Reading
Section titled “Further Reading”- UV Integration Architecture - Architectural decisions
- Virtual Environment API - Python API reference
- Working with Virtual Environments - Usage guide
- UV Documentation - Official UV documentation