setup_venv.ps1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # =============================================================================
  2. # Script tout-en-un : créer venv + installer requirements.txt
  3. # Usage: .\setup_venv.ps1
  4. # Si erreur psycopg2 (Python 3.13 Windows): .\setup_venv.ps1 -SkipPsycopg
  5. # =============================================================================
  6. param(
  7. [switch]$SkipPsycopg
  8. )
  9. $ErrorActionPreference = "Stop"
  10. Set-Location $PSScriptRoot
  11. # 1. Créer le venv s'il n'existe pas
  12. if (-not (Test-Path "venv\Scripts\Activate.ps1")) {
  13. Write-Host "Création du venv..." -ForegroundColor Cyan
  14. py -m venv venv
  15. if ($LASTEXITCODE -ne 0) {
  16. Write-Host "Erreur: Python non trouvé. Utilisez 'py' ou 'python3'." -ForegroundColor Red
  17. exit 1
  18. }
  19. } else {
  20. Write-Host "Le venv existe déjà." -ForegroundColor Gray
  21. }
  22. # 2. Activer le venv
  23. Write-Host "`nActivation du venv..." -ForegroundColor Cyan
  24. & .\venv\Scripts\Activate.ps1
  25. # 3. psycopg2 (Windows: wheel obligatoire pour Python 3.13)
  26. if (-not $SkipPsycopg) {
  27. Write-Host "`n1. psycopg2-binary (wheel Windows)..." -ForegroundColor Cyan
  28. pip install "psycopg2-binary>=2.9.9" --only-binary :all:
  29. if ($LASTEXITCODE -ne 0) {
  30. Write-Host " Pas de wheel. Relancez avec: .\setup_venv.ps1 -SkipPsycopg (SQLite)" -ForegroundColor Yellow
  31. $SkipPsycopg = $true
  32. }
  33. }
  34. # 4. Dépendances du requirements.txt
  35. Write-Host "`n2. Installation de requirements.txt..." -ForegroundColor Cyan
  36. if ($SkipPsycopg) {
  37. $filtered = Get-Content requirements.txt | Where-Object { $_ -notmatch 'psycopg2' }
  38. $temp = [System.IO.Path]::GetTempFileName()
  39. $filtered | Set-Content $temp
  40. pip install -r $temp
  41. Remove-Item $temp
  42. } else {
  43. pip install -r requirements.txt
  44. }
  45. # 5. Override Windows: python-magic-bin
  46. Write-Host "`n3. python-magic-bin (Windows)..." -ForegroundColor Cyan
  47. pip uninstall python-magic -y 2>$null
  48. pip install python-magic-bin
  49. # 6. Post-install: spaCy + NLTK
  50. Write-Host "`n4. Modèle spaCy + NLTK..." -ForegroundColor Cyan
  51. python -m spacy download fr_core_news_sm
  52. python -c "import nltk; nltk.download('punkt'); nltk.download('punkt_tab')"
  53. Write-Host "`n=== Installation terminée ===" -ForegroundColor Green
  54. Write-Host "Pour lancer l'app: .\run_local.ps1" -ForegroundColor Green