Fix Windows deployment scripts for missing Python dependencies
Issues fixed: 1. Build-Frontend.ps1: Add verification that requirements.txt is included in deployment package - Prevents incomplete packages that cause ModuleNotFoundError on server - Throws error if critical files are missing before package is transferred 2. Deploy-ROA2WEB.ps1: Auto-detect first deployment and force install dependencies - Automatically sets ForceInstallDependencies=true on first deployment - Add -ForceInstallDependencies parameter for manual override - Better error handling and validation for pip install - Shows clear error messages with manual recovery instructions This fixes the "ModuleNotFoundError: No module named 'httpx'" error that occurred when deploying to Windows Server without explicitly forcing dependency installation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -281,6 +281,15 @@ function Copy-BackendFiles {
|
||||
|
||||
$backendFiles = Get-ChildItem -Path $DestPath -Recurse -File
|
||||
Write-Success "Copied $(($backendFiles).Count) backend files"
|
||||
|
||||
# Verify critical files are present
|
||||
$requirementsTxt = Join-Path $DestPath "requirements.txt"
|
||||
if (-not (Test-Path $requirementsTxt)) {
|
||||
Write-Error "CRITICAL: requirements.txt not found in backend package!"
|
||||
Write-Host " Expected: $requirementsTxt" -ForegroundColor Red
|
||||
throw "Backend package incomplete - missing requirements.txt"
|
||||
}
|
||||
Write-Success "Verified: requirements.txt present"
|
||||
}
|
||||
|
||||
function New-DeploymentPackage {
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
.PARAMETER UpdateFrontend
|
||||
Update frontend files (default: true)
|
||||
|
||||
.PARAMETER ForceInstallDependencies
|
||||
Force reinstall all Python dependencies even if requirements.txt hasn't changed (default: false)
|
||||
|
||||
.EXAMPLE
|
||||
cd C:\Deploy\ROA2WEB\scripts
|
||||
.\Deploy-ROA2WEB.ps1
|
||||
@@ -36,6 +39,10 @@
|
||||
.\Deploy-ROA2WEB.ps1 -UpdateBackend -UpdateFrontend:$false
|
||||
Update only backend files
|
||||
|
||||
.EXAMPLE
|
||||
.\Deploy-ROA2WEB.ps1 -ForceInstallDependencies $true
|
||||
Update files and force reinstall all Python dependencies
|
||||
|
||||
.NOTES
|
||||
Author: ROA2WEB Team
|
||||
Requires: PowerShell 5.1+, Administrator privileges
|
||||
@@ -48,7 +55,8 @@ param(
|
||||
[bool]$BackupEnabled = $true,
|
||||
[bool]$RestartService = $true,
|
||||
[bool]$UpdateBackend = $true,
|
||||
[bool]$UpdateFrontend = $true
|
||||
[bool]$UpdateFrontend = $true,
|
||||
[bool]$ForceInstallDependencies = $false
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -242,27 +250,51 @@ function Update-BackendFiles {
|
||||
|
||||
Write-Success "Backend files updated"
|
||||
|
||||
# Check if requirements.txt changed
|
||||
# Check if requirements.txt changed or if force install is requested
|
||||
$sourceReq = Join-Path $sourceBackend "requirements.txt"
|
||||
$destReq = Join-Path $Config.BackendPath "requirements.txt"
|
||||
|
||||
if (Test-Path $sourceReq) {
|
||||
$sourceHash = (Get-FileHash $sourceReq).Hash
|
||||
$destHash = if (Test-Path $destReq) { (Get-FileHash $destReq).Hash } else { "" }
|
||||
$requirementsChanged = $sourceHash -ne $destHash
|
||||
|
||||
if ($requirementsChanged -or $ForceInstallDependencies) {
|
||||
if ($ForceInstallDependencies) {
|
||||
Write-Step "Force installing Python dependencies..."
|
||||
} else {
|
||||
Write-Step "Requirements changed, updating Python dependencies..."
|
||||
}
|
||||
|
||||
if ($sourceHash -ne $destHash) {
|
||||
Write-Step "Requirements changed, updating Python dependencies..."
|
||||
Copy-Item -Path $sourceReq -Destination $destReq -Force
|
||||
|
||||
try {
|
||||
# Verify Python is available
|
||||
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
|
||||
if (-not $pythonCmd) {
|
||||
Write-Error "Python not found in PATH. Please ensure Python 3.11+ is installed."
|
||||
throw "Python not found"
|
||||
}
|
||||
|
||||
Write-Host " Installing/upgrading dependencies from: $destReq" -ForegroundColor Gray
|
||||
& python -m pip install -r $destReq --upgrade
|
||||
Write-Success "Python dependencies updated"
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Success "Python dependencies installed successfully"
|
||||
} else {
|
||||
Write-Error "pip install failed with exit code: $LASTEXITCODE"
|
||||
throw "Dependency installation failed"
|
||||
}
|
||||
} catch {
|
||||
Write-Error "Failed to update Python dependencies: $_"
|
||||
Write-Warning "Try running manually: python -m pip install -r $destReq"
|
||||
throw
|
||||
}
|
||||
} else {
|
||||
Write-Success "Python dependencies unchanged"
|
||||
}
|
||||
} else {
|
||||
Write-Warning "requirements.txt not found in source package"
|
||||
}
|
||||
} catch {
|
||||
Write-Error "Failed to update backend files: $_"
|
||||
@@ -466,6 +498,13 @@ function Main {
|
||||
}
|
||||
Write-Success "Installation path exists"
|
||||
|
||||
# Check if this is first deployment (no backend files yet)
|
||||
$isFirstDeployment = -not (Test-Path (Join-Path $Config.BackendPath "app"))
|
||||
if ($isFirstDeployment) {
|
||||
Write-Warning "First deployment detected - will install all dependencies"
|
||||
$script:ForceInstallDependencies = $true
|
||||
}
|
||||
|
||||
try {
|
||||
# Deployment steps
|
||||
$backupPath = Backup-CurrentDeployment
|
||||
|
||||
Reference in New Issue
Block a user