Skip to content

Commit e5a449b

Browse files
committed
update "install.ps1"
- Add aggiunta funzione di aggiunta al PATH di windows per utilizzare nativamente Pip e Python
1 parent 0226d83 commit e5a449b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

install.ps1

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,92 @@ if ($versionToUse -ne "") {
282282
Write-Host "ERRORE: Nessuna versione Python utilizzabile trovata!"
283283
}
284284

285+
# Funzione per aggiungere Python e pip al PATH di Windows
286+
function Add-PythonToPath {
287+
param (
288+
[string]$pythonVersion
289+
)
290+
291+
Write-Host "Aggiungendo Python $pythonVersion al PATH di Windows..."
292+
293+
try {
294+
# Ottieni il percorso di installazione di Python
295+
$pythonOutput = py -$pythonVersion -c "import sys; print(sys.executable)" 2>$null
296+
297+
if ($pythonOutput) {
298+
$pythonPath = Split-Path $pythonOutput
299+
$scriptsPath = Join-Path $pythonPath "Scripts"
300+
301+
Write-Host "Percorso Python: $pythonPath"
302+
Write-Host "Percorso Scripts: $scriptsPath"
303+
304+
# Ottieni il PATH corrente
305+
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
306+
307+
# Controlla se i percorsi sono già nel PATH
308+
$pathsToAdd = @()
309+
310+
if ($currentPath -notlike "*$pythonPath*") {
311+
$pathsToAdd += $pythonPath
312+
Write-Host "Aggiungendo $pythonPath al PATH..."
313+
} else {
314+
Write-Host "Python path già presente nel PATH."
315+
}
316+
317+
if ($currentPath -notlike "*$scriptsPath*") {
318+
$pathsToAdd += $scriptsPath
319+
Write-Host "Aggiungendo $scriptsPath al PATH..."
320+
} else {
321+
Write-Host "Scripts path già presente nel PATH."
322+
}
323+
324+
# Aggiungi i percorsi al PATH se necessario
325+
if ($pathsToAdd.Count -gt 0) {
326+
$newPath = $currentPath
327+
foreach ($pathToAdd in $pathsToAdd) {
328+
if ($newPath -ne "") {
329+
$newPath += ";"
330+
}
331+
$newPath += $pathToAdd
332+
}
333+
334+
# Imposta il nuovo PATH per l'utente corrente
335+
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
336+
337+
# Aggiorna il PATH nella sessione corrente
338+
$env:PATH = $newPath
339+
340+
Write-Host "PATH aggiornato con successo!"
341+
Write-Host "I percorsi Python sono ora disponibili globalmente."
342+
343+
return $true
344+
} else {
345+
Write-Host "Tutti i percorsi Python sono già nel PATH."
346+
return $true
347+
}
348+
} else {
349+
Write-Host "Impossibile ottenere il percorso di Python $pythonVersion"
350+
return $false
351+
}
352+
}
353+
catch {
354+
Write-Host "Errore durante l'aggiunta di Python al PATH: $($_.Exception.Message)"
355+
return $false
356+
}
357+
}
358+
359+
# Aggiungi la versione Python principale al PATH
360+
if ($versionToUse -ne "") {
361+
Write-Host "Configurazione PATH per Python $versionToUse..."
362+
$pathResult = Add-PythonToPath -pythonVersion $versionToUse
363+
364+
if ($pathResult) {
365+
Write-Host "PATH configurato correttamente!"
366+
} else {
367+
Write-Host "Problemi nella configurazione del PATH, continuo comunque..."
368+
}
369+
}
370+
285371
# Visualizzare il messaggio "Attendere..." per 2 secondi
286372
Write-Host ""
287373
Write-Host "Attendere..."
@@ -309,11 +395,18 @@ if (Test-Path $mainScript) {
309395
if ($executionVersion -ne "") {
310396
Write-Host "Eseguo main.py con Python $executionVersion..."
311397

398+
# Aggiungi anche questa versione al PATH se diversa da quella usata per le dipendenze
399+
if ($executionVersion -ne $versionToUse) {
400+
Write-Host "Configurazione PATH per Python $executionVersion..."
401+
Add-PythonToPath -pythonVersion $executionVersion
402+
}
403+
312404
# Verifica finale che la versione sia utilizzabile
313405
try {
314406
$testResult = py -$executionVersion --version 2>$null
315407
if ($testResult -match "Python $executionVersion") {
316408
# Esegui main.py con la versione Python corretta
409+
Write-Host "Avvio di main.py..."
317410
py -$executionVersion $mainScript
318411
} else {
319412
Write-Host "Versione $executionVersion non verificabile, uso comando generico..."

0 commit comments

Comments
 (0)