-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathpython_installer.bat
More file actions
135 lines (120 loc) · 4.73 KB
/
python_installer.bat
File metadata and controls
135 lines (120 loc) · 4.73 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
@echo off
setlocal enabledelayedexpansion
title Void-Tools Setup
color 0c
echo.
echo ^<^<^< VOID-TOOLS SETUP ^>^>^>
echo ================================
echo.
:: ------------------------------------------------
:: 1. Kill active Python processes
:: ------------------------------------------------
echo [1/6] ^> Killing Python processes...
taskkill /f /im python.exe >nul 2>nul
taskkill /f /im pythonw.exe >nul 2>nul
taskkill /f /im pip.exe >nul 2>nul
timeout /t 1 /nobreak >nul
echo Done.
:: ------------------------------------------------
:: 2. Wipe all pip packages
:: ------------------------------------------------
echo [2/6] ^> Wiping pip packages...
python -m pip freeze > "%TEMP%\pip_list.txt" 2>nul
python -m pip uninstall -y -r "%TEMP%\pip_list.txt" >nul 2>nul
del "%TEMP%\pip_list.txt" >nul 2>nul
echo Done.
:: ------------------------------------------------
:: 3. Uninstall Python (registry + MSI)
:: ------------------------------------------------
echo [3/6] ^> Uninstalling Python...
for /f "tokens=*" %%K in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall" 2^>nul') do (
for /f "tokens=2*" %%A in ('reg query "%%K" /v "DisplayName" 2^>nul ^| findstr /i "Python"') do (
for /f "tokens=2*" %%C in ('reg query "%%K" /v "UninstallString" 2^>nul') do (
start /wait "" cmd /c "%%D /quiet /norestart" >nul 2>nul
)
)
)
for /f "delims=" %%I in ('wmic product where "Name like ''Python%%''" get IdentifyingNumber /format:value 2^>nul ^| findstr "IdentifyingNumber"') do (
set "LINE=%%I"
set "GUID=!LINE:IdentifyingNumber=!"
set "GUID=!GUID:~1!"
msiexec /x !GUID! /quiet /norestart >nul 2>nul
)
echo Done.
:: ------------------------------------------------
:: 4. Delete leftover folders
:: ------------------------------------------------
echo [4/6] ^> Removing leftover folders...
for %%D in (
"%LOCALAPPDATA%\Programs\Python"
"%APPDATA%\Python"
"%LOCALAPPDATA%\pip"
) do (
if exist "%%~D" (
takeown /f "%%~D" /r /d y >nul 2>nul
icacls "%%~D" /grant "%USERNAME%":F /t >nul 2>nul
rd /s /q "%%~D" >nul 2>nul
)
)
echo Done.
:: ------------------------------------------------
:: 5. Clean registry + user PATH
:: ------------------------------------------------
echo [5/6] ^> Cleaning registry and PATH...
reg delete "HKCU\Software\Python" /f >nul 2>nul
powershell -NoProfile -NonInteractive -Command "$u=[System.Environment]::GetEnvironmentVariable('PATH','User'); $c=($u -split ';' | Where-Object {$_ -notmatch '(?i)python' -and $_ -notmatch '(?i)Scripts' -and $_ -ne ''} | Select-Object -Unique) -join ';'; [System.Environment]::SetEnvironmentVariable('PATH',$c,'User');" >nul 2>nul
echo Done.
echo.
echo ================================
echo Cleanup complete. Setting up...
echo ================================
echo.
:: ------------------------------------------------
:: 6. Refresh PATH + locate Python
:: ------------------------------------------------
for /f "skip=2 tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "USERPATH=%%B"
if defined USERPATH set "PATH=%USERPATH%;%PATH%"
set "PY=python"
where python >nul 2>nul
if errorlevel 1 (
for /d %%D in ("%LOCALAPPDATA%\Programs\Python\Python*") do (
if exist "%%D\python.exe" set "PY=%%D\python.exe"
)
)
:: Check Python, install if missing
"%PY%" --version >nul 2>&1
if errorlevel 1 goto :install_python
goto :python_ready
:install_python
echo [6/6] ^> Python not found, downloading...
curl -L "https://www.python.org/ftp/python/3.11.5/python-3.11.5-amd64.exe" -o "%APPDATA%\py_setup.exe"
if not exist "%APPDATA%\py_setup.exe" (
echo.
echo [!] Download failed. Check your connection.
pause & exit /b 1
)
echo Installing Python 3.11.5...
start /wait "" "%APPDATA%\py_setup.exe" /quiet InstallAllUsers=0 PrependPath=1 Include_test=0 Include_pip=1 Include_doc=0 Include_launcher=1
del "%APPDATA%\py_setup.exe" >nul 2>nul
for /f "skip=2 tokens=2*" %%A in ('reg query "HKCU\Environment" /v PATH 2^>nul') do set "USERPATH=%%B"
if defined USERPATH set "PATH=%USERPATH%;%PATH%"
for /d %%D in ("%LOCALAPPDATA%\Programs\Python\Python*") do (
if exist "%%D\python.exe" set "PY=%%D\python.exe"
)
echo Python 3.11.5 installed.
:python_ready
echo [6/6] ^> Python detected:
"%PY%" --version
echo.
echo Checking modules...
"%PY%" -c "import sys, os, time, random, string, json, threading, itertools, shutil, re, queue, webbrowser, concurrent.futures" >nul 2>&1
if errorlevel 1 (
echo [!] Missing stdlib module. Reinstall Python.
pause & exit /b 1
)
"%PY%" -c "import requests" >nul 2>&1
if errorlevel 1 (
echo Installing requests...
"%PY%" -m pip install requests --quiet
)
echo All modules OK.