# MOTM Flask Application - Virtual Environment Setup (PowerShell) # Run this script in PowerShell: .\setup_venv.ps1 Write-Host "MOTM Flask Application - Virtual Environment Setup" -ForegroundColor Green Write-Host "=" * 60 -ForegroundColor Green # Check Python installation Write-Host "`nšŸ Checking Python installation..." -ForegroundColor Yellow $pythonCommands = @('python', 'python3', 'py') $pythonCmd = $null foreach ($cmd in $pythonCommands) { try { $version = & $cmd --version 2>$null if ($LASTEXITCODE -eq 0) { $pythonCmd = $cmd Write-Host "āœ… Found Python: $version" -ForegroundColor Green break } } catch { # Continue to next command } } if (-not $pythonCmd) { Write-Host "āŒ Python not found. Please install Python 3.7+ from python.org" -ForegroundColor Red Write-Host " Make sure to check 'Add Python to PATH' during installation" -ForegroundColor Yellow Read-Host "Press Enter to exit" exit 1 } # Check if virtual environment already exists $venvDir = "venv" if (Test-Path $venvDir) { Write-Host "`n⚠ Virtual environment '$venvDir' already exists" -ForegroundColor Yellow $recreate = Read-Host "Do you want to recreate it? (y/N)" if ($recreate -match '^[yY]') { Write-Host "šŸ—‘ļø Removing existing virtual environment..." -ForegroundColor Yellow Remove-Item -Recurse -Force $venvDir } else { Write-Host "Using existing virtual environment..." -ForegroundColor Green $skipCreation = $true } } # Create virtual environment if (-not $skipCreation) { Write-Host "`nšŸ“¦ Creating virtual environment in '$venvDir'..." -ForegroundColor Yellow try { & $pythonCmd -m venv $venvDir if ($LASTEXITCODE -eq 0) { Write-Host "āœ… Virtual environment created successfully!" -ForegroundColor Green } else { throw "Virtual environment creation failed" } } catch { Write-Host "āŒ Failed to create virtual environment: $_" -ForegroundColor Red Read-Host "Press Enter to exit" exit 1 } } # Install dependencies Write-Host "`nšŸ“š Installing dependencies..." -ForegroundColor Yellow $pipCmd = Join-Path $venvDir "Scripts\pip.exe" if (-not (Test-Path $pipCmd)) { $pipCmd = Join-Path $venvDir "Scripts\pip" } try { # Upgrade pip first Write-Host "šŸ”„ Upgrading pip..." -ForegroundColor Yellow & $pipCmd install --upgrade pip # Install requirements Write-Host "šŸ“¦ Installing application dependencies..." -ForegroundColor Yellow & $pipCmd install -r requirements.txt if ($LASTEXITCODE -eq 0) { Write-Host "āœ… Dependencies installed successfully!" -ForegroundColor Green } else { throw "Dependencies installation failed" } } catch { Write-Host "āŒ Failed to install dependencies: $_" -ForegroundColor Red Read-Host "Press Enter to exit" exit 1 } # Create convenience scripts Write-Host "`nšŸ“ Creating convenience scripts..." -ForegroundColor Yellow # Update the batch files to use the correct Python command $activateScript = @" @echo off echo šŸ Activating MOTM Virtual Environment... call venv\Scripts\activate.bat echo āœ… Virtual environment activated! echo. echo šŸš€ To start the MOTM application, run: echo $pythonCmd main.py echo. echo šŸ”§ To deactivate, run: echo deactivate "@ $runScript = @" @echo off echo šŸ Starting MOTM Application... call venv\Scripts\activate.bat $pythonCmd main.py pause "@ $activateScript | Out-File -FilePath "activate_motm.bat" -Encoding ASCII $runScript | Out-File -FilePath "run_motm.bat" -Encoding ASCII Write-Host "āœ… Convenience scripts created!" -ForegroundColor Green # Print completion message Write-Host "`n" + "=" * 60 -ForegroundColor Green Write-Host "šŸŽ‰ MOTM Virtual Environment Setup Complete!" -ForegroundColor Green Write-Host "=" * 60 -ForegroundColor Green Write-Host "`nšŸ“‹ To use the virtual environment:" -ForegroundColor Cyan Write-Host " 1. Activate: .\activate_motm.bat" -ForegroundColor White Write-Host " 2. Run app: .\run_motm.bat" -ForegroundColor White Write-Host " 3. Deactivate: deactivate" -ForegroundColor White Write-Host "`nšŸ”§ Manual activation:" -ForegroundColor Cyan Write-Host " venv\Scripts\activate.bat" -ForegroundColor White Write-Host " $pythonCmd main.py" -ForegroundColor White Write-Host "`n🌐 The application will be available at: http://localhost:5000" -ForegroundColor Cyan Write-Host "`nšŸ“š For development:" -ForegroundColor Cyan Write-Host " - Activate the venv before installing new packages" -ForegroundColor White Write-Host " - Use 'pip install ' to add dependencies" -ForegroundColor White Write-Host " - Update requirements.txt with 'pip freeze > requirements.txt'" -ForegroundColor White Write-Host "`nšŸš€ Ready to start! Run: .\run_motm.bat" -ForegroundColor Green Read-Host "`nPress Enter to exit"