-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_python.ps1
More file actions
51 lines (42 loc) · 2.31 KB
/
Copy pathinstall_python.ps1
File metadata and controls
51 lines (42 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Ustawienie, aby skrypt zatrzymał się w przypadku błędu
$ErrorActionPreference = "Stop"
Write-Host "--- Rozpoczynam konfigurację środowiska Python na Windows 11 ---" -ForegroundColor Cyan
# 1. Sprawdzenie uprawnień Administratora
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-not $isAdmin) {
Write-Warning "Skrypt nie ma uprawnień administratora."
Write-Warning "Proszę uruchom PowerShell jako Administrator i spróbuj ponownie."
Break
}
# 2. Instalacja najnowszego Pythona 3 przez Winget
# --id Python.Python.3 : Wskazuje na najnowszą stabilną wersję Pythona 3
# --scope machine : Instaluje dla wszystkich użytkowników
# --override : Wymusza dodanie do PATH (kluczowe!)
try {
Write-Host "Trwa pobieranie i instalacja najnowszego Pythona..." -ForegroundColor Yellow
winget install -e --id Python.Python.3 --scope machine --accept-package-agreements --accept-source-agreements --override "PrependPath=1 Include_test=0"
Write-Host "Instalacja zakończona sukcesem." -ForegroundColor Green
}
catch {
Write-Error "Wystąpił błąd podczas instalacji przez Winget. Upewnij się, że masz połączenie z internetem."
Break
}
# 3. Odświeżenie zmiennych środowiskowych w bieżącej sesji (próba)
# Uwaga: Czasami i tak wymagany jest restart terminala.
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# 4. Weryfikacja instalacji
Write-Host "--- Weryfikacja instalacji ---" -ForegroundColor Cyan
try {
# Sprawdzenie wersji
$pyVersion = python --version
Write-Host "Zainstalowano: $pyVersion" -ForegroundColor Green
# Aktualizacja PIP (menedżera pakietów)
Write-Host "Aktualizacja PIP do najnowszej wersji..." -ForegroundColor Yellow
python -m pip install --upgrade pip
Write-Host "PIP jest gotowy do pracy." -ForegroundColor Green
}
catch {
Write-Warning "Python został zainstalowany, ale obecna sesja PowerShell go nie widzi."
Write-Warning "ZAMKNIJ to okno i otwórz nowe okno PowerShell, aby zacząć używać komendy 'python'."
}
Write-Host "--- Gotowe! ---" -ForegroundColor Cyan