| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- # =============================================================================
- # Script tout-en-un : créer venv + installer requirements.txt
- # Usage: .\setup_venv.ps1
- # Si erreur psycopg2 (Python 3.13 Windows): .\setup_venv.ps1 -SkipPsycopg
- # =============================================================================
- param(
- [switch]$SkipPsycopg
- )
- $ErrorActionPreference = "Stop"
- Set-Location $PSScriptRoot
- # 1. Créer le venv s'il n'existe pas
- if (-not (Test-Path "venv\Scripts\Activate.ps1")) {
- Write-Host "Création du venv..." -ForegroundColor Cyan
- py -m venv venv
- if ($LASTEXITCODE -ne 0) {
- Write-Host "Erreur: Python non trouvé. Utilisez 'py' ou 'python3'." -ForegroundColor Red
- exit 1
- }
- } else {
- Write-Host "Le venv existe déjà." -ForegroundColor Gray
- }
- # 2. Activer le venv
- Write-Host "`nActivation du venv..." -ForegroundColor Cyan
- & .\venv\Scripts\Activate.ps1
- # 3. psycopg2 (Windows: wheel obligatoire pour Python 3.13)
- if (-not $SkipPsycopg) {
- Write-Host "`n1. psycopg2-binary (wheel Windows)..." -ForegroundColor Cyan
- pip install "psycopg2-binary>=2.9.9" --only-binary :all:
- if ($LASTEXITCODE -ne 0) {
- Write-Host " Pas de wheel. Relancez avec: .\setup_venv.ps1 -SkipPsycopg (SQLite)" -ForegroundColor Yellow
- $SkipPsycopg = $true
- }
- }
- # 4. Dépendances du requirements.txt
- Write-Host "`n2. Installation de requirements.txt..." -ForegroundColor Cyan
- if ($SkipPsycopg) {
- $filtered = Get-Content requirements.txt | Where-Object { $_ -notmatch 'psycopg2' }
- $temp = [System.IO.Path]::GetTempFileName()
- $filtered | Set-Content $temp
- pip install -r $temp
- Remove-Item $temp
- } else {
- pip install -r requirements.txt
- }
- # 5. Override Windows: python-magic-bin
- Write-Host "`n3. python-magic-bin (Windows)..." -ForegroundColor Cyan
- pip uninstall python-magic -y 2>$null
- pip install python-magic-bin
- # 6. Post-install: spaCy + NLTK
- Write-Host "`n4. Modèle spaCy + NLTK..." -ForegroundColor Cyan
- python -m spacy download fr_core_news_sm
- python -c "import nltk; nltk.download('punkt')"
- Write-Host "`n=== Installation terminée ===" -ForegroundColor Green
- Write-Host "Pour lancer l'app: .\run_local.ps1" -ForegroundColor Green
|