OnyxMunk/AudioForge
0
1# Setup Python 3.11 Environment for AudioForge ML Dependencies
2# AudioCraft requires Python 3.11 (doesn't support 3.13)
3
4$Colors = @{
5 Red = "Red"
6 Green = "Green"
7 Yellow = "Yellow"
8 Blue = "Cyan"
9}
10
11function Write-Info { Write-Host "[INFO] $args" -ForegroundColor $Colors.Blue }
12function Write-Success { Write-Host "[SUCCESS] $args" -ForegroundColor $Colors.Green }
13function Write-Warning { Write-Host "[WARNING] $args" -ForegroundColor $Colors.Yellow }
14function Write-Error { Write-Host "[ERROR] $args" -ForegroundColor $Colors.Red }
15
16Write-Host "`n╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
17Write-Host "║ Python 3.11 Setup for ML Dependencies ║" -ForegroundColor Cyan
18Write-Host "╚═══════════════════════════════════════════════════════════╝`n" -ForegroundColor Cyan
19
20$ProjectRoot = Split-Path -Parent $PSScriptRoot
21$BackendPath = Join-Path $ProjectRoot "backend"
22$VenvPath = Join-Path $BackendPath ".venv311"
23
24# Check for Python 3.11
25Write-Info "Checking for Python 3.11..."
26
27$python311 = $null
28$python311Path = $null
29
30# Try py launcher first
31try {
32 $version = py -3.11 --version 2>&1
33 if ($LASTEXITCODE -eq 0) {
34 $python311 = "py -3.11"
35 Write-Success "Found Python 3.11 via py launcher: $version"
36 }
37} catch {}
38
39# Try direct python3.11
40if (-not $python311) {
41 try {
42 $version = python3.11 --version 2>&1
43 if ($LASTEXITCODE -eq 0) {
44 $python311 = "python3.11"
45 Write-Success "Found Python 3.11: $version"
46 }
47 } catch {}
48}
49
50# Try python -V to check current version
51if (-not $python311) {
52 try {
53 $currentVersion = python --version 2>&1
54 if ($currentVersion -match "3\.11") {
55 $python311 = "python"
56 Write-Success "Current Python is 3.11: $currentVersion"
57 } else {
58 Write-Warning "Current Python is not 3.11: $currentVersion"
59 }
60 } catch {}
61}
62
63if (-not $python311) {
64 Write-Error "Python 3.11 not found!"
65 Write-Host ""
66 Write-Host "📋 To install Python 3.11:" -ForegroundColor Cyan
67 Write-Host "1. Download from: https://www.python.org/downloads/release/python-3110/" -ForegroundColor White
68 Write-Host "2. Or use Windows Store: Search for 'Python 3.11'" -ForegroundColor White
69 Write-Host "3. Or use py launcher: py -3.11 -m pip install --upgrade pip" -ForegroundColor White
70 Write-Host ""
71 Write-Host "After installing Python 3.11, run this script again." -ForegroundColor Yellow
72 exit 1
73}
74
75# Create virtual environment
76Write-Info "Creating Python 3.11 virtual environment..."
77Set-Location $BackendPath
78
79if (Test-Path $VenvPath) {
80 Write-Warning "Virtual environment .venv311 already exists"
81 $overwrite = Read-Host "Overwrite? (y/N)"
82 if ($overwrite -ne "y") {
83 Write-Info "Skipping virtual environment creation"
84 } else {
85 Remove-Item -Recurse -Force $VenvPath
86 & $python311 -m venv .venv311
87 Write-Success "Virtual environment created"
88 }
89} else {
90 & $python311 -m venv .venv311
91 Write-Success "Virtual environment created"
92}
93
94# Activate and install dependencies
95Write-Info "Installing ML dependencies..."
96$activateScript = Join-Path $VenvPath "Scripts\Activate.ps1"
97
98if (-not (Test-Path $activateScript)) {
99 Write-Error "Activation script not found: $activateScript"
100 exit 1
101}
102
103# Install uv first
104Write-Info "Installing uv package manager..."
105& "$VenvPath\Scripts\python.exe" -m pip install --upgrade pip
106& "$VenvPath\Scripts\python.exe" -m pip install uv
107
108# Install ML dependencies
109Write-Info "Installing ML dependencies (this may take 5-10 minutes)..."
110Write-Warning "This will download ~2GB of files (PyTorch, AudioCraft models)"
111
112& "$VenvPath\Scripts\uv.exe" pip install -e ".[ml]"
113
114if ($LASTEXITCODE -eq 0) {
115 Write-Success "ML dependencies installed successfully!"
116 Write-Host ""
117 Write-Host "📝 To use this environment:" -ForegroundColor Cyan
118 Write-Host " cd backend" -ForegroundColor White
119 Write-Host " .venv311\Scripts\Activate.ps1" -ForegroundColor White
120 Write-Host " uvicorn app.main:app --reload" -ForegroundColor White
121 Write-Host ""
122} else {
123 Write-Error "Failed to install ML dependencies"
124 Write-Host "Check the error messages above for details." -ForegroundColor Yellow
125 exit 1
126}
127 