UV Installation and Management
This document explains how Angreal manages the UV binary for ultra-fast virtual environment operations.
UV is automatically installed when Angreal needs it, with no manual setup required.
UV installation is triggered automatically when:
- First Virtual Environment Operation: Any
VirtualEnv
class usage - Module Import: When
angreal.integrations.venv
is imported - Decorator Usage: When
@venv_required
is applied to a function - Binary Not Found: When UV is not available in the system PATH
curl -LsSf https://astral.sh/uv/install.sh | sh
Features:
- Downloads latest stable UV release
- Installs to
~/.local/bin/
(added to PATH) - Works on macOS and Linux distributions
- Uses secure HTTPS download
irm https://astral.sh/uv/install.ps1 | iex
Features:
- Downloads Windows-specific UV binary
- Installs to user-accessible location
- Automatically updates PATH environment variable
- Compatible with PowerShell 5.0+
After installation, Angreal automatically verifies:
- Binary Availability: UV command is accessible via PATH
- Version Check: UV responds to
--version
flag - Functionality Test: Basic UV operations work correctly
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
# Unix/macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
irm https://astral.sh/uv/install.ps1 | iex
Homebrew (macOS/Linux):
brew install uv
Scoop (Windows):
scoop install uv
Cargo (All Platforms):
cargo install uv
pip install uv
Note: The pip installation may be slower than binary installations.
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 |
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"
RuntimeError: UV installation failed
Solutions:
- Check internet connectivity
- Verify firewall/proxy settings allow HTTPS downloads
- Try manual installation
- Use alternative package managers
Permission denied: Cannot install UV
Solutions:
- Ensure write permissions to installation directory
- Install to user directory (default behavior)
- Use
sudo
for system-wide installation (not recommended)
UV binary not found after installation
Solutions:
- Restart terminal/shell session
- Manually add UV location to PATH
- Verify installation directory is correct
If multiple UV installations exist:
from angreal.integrations.venv import VirtualEnv
# Check which UV version is being used
version = 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
Angreal works with any modern UV version, but newer versions offer better performance:
# Update UV manually
curl -LsSf https://astral.sh/uv/install.sh | sh # Unix/macOS
irm https://astral.sh/uv/install.ps1 | iex # Windows
UV uses caching for optimal performance. Configure cache settings:
# Set custom cache directory
export UV_CACHE_DIR="/path/to/large/disk/cache"
# Cache size will grow over time - monitor disk usage
du -sh $UV_CACHE_DIR
For faster package downloads:
# Use UV's built-in parallel downloads (default)
# No configuration needed - UV automatically optimizes
# For corporate networks, configure proxy if needed
export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080
- All UV downloads use HTTPS encryption
- Official installation scripts are cryptographically signed
- UV binaries are verified during installation
- Angreal uses secure subprocess calls (no shell injection vulnerabilities)
- UV binary path is validated before execution
- All UV operations use proper argument arrays
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
from angreal.integrations.venv import VirtualEnv
from 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
# Usage
if check_uv_status():
print("UV is ready for use!")
import subprocess
import sys
from 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 tasks
import 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)
Include UV health checks in your project setup:
import angreal
from 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}")
UV updates automatically when using the installation scripts. For maintenance:
# Check current version
uv --version
# Update to latest version
curl -LsSf https://astral.sh/uv/install.sh | sh # Unix/macOS
irm https://astral.sh/uv/install.ps1 | iex # Windows
# Clean UV cache if needed (saves disk space)
uv cache clean
- UV Integration Architecture - Architectural decisions
- Virtual Environment API - Python API reference
- Working with Virtual Environments - Usage guide
- UV Documentation - Official UV documentation