-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_requirements.bat
68 lines (57 loc) · 2.09 KB
/
install_requirements.bat
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
@echo off
REM Check if python3 is available
python3 --version >nul 2>nul
if %errorlevel% equ 0 (
set PYTHON_COMMAND=python3
) else (
REM Search for python.exe in user's directory (AppData)
for /f "delims=" %%i in ('dir /b /s "%APPDATA%\Python\Python*" ^| findstr /i /r "python[.]exe$"') do (
set PYTHON_COMMAND=%%i
goto :found_python
)
REM Search for python.exe in Program Files directory
for /f "delims=" %%i in ('dir /b /s "C:\Program Files\Python*" ^| findstr /i /r "python[.]exe$"') do (
set PYTHON_COMMAND=%%i
goto :found_python
)
REM Search for python.exe in local programs directory (AppData)
for /f "delims=" %%i in ('dir /b /s "%LOCALAPPDATA%\Programs\Python\Python*" ^| findstr /i /r "python[.]exe$"') do (
set PYTHON_COMMAND=%%i
goto :found_python
)
REM If Python is not found, display error message and exit
echo Error: Python interpreter not found.
echo Please install Python and make sure it is added to the system PATH.
echo.
echo After your confirmation the script will stop and the console may be closed.
pause
exit /b 1
)
REM Label to jump to when Python is found
:found_python
REM Define the location of the requirements.txt file
set REQUIREMENTS_FILE=requirements.txt
REM Check if pip is available
%PYTHON_COMMAND% -m pip --version >nul 2>&1
if %errorlevel% neq 0 (
echo Error: pip is not installed.
echo Please install pip to continue.
echo.
echo After your confirmation the script will stop and the console may be closed.
pause
exit /b 1
)
REM Install requirements from requirements.txt
%PYTHON_COMMAND% -m pip install -r %REQUIREMENTS_FILE%
if %errorlevel% neq 0 (
echo Error: Failed to install requirements using pip.
echo Please check the requirements.txt file and try again.
echo.
echo After your confirmation the script will stop and the console may be closed.
pause
exit /b 1
)
REM Display message and wait for user input to close the console
echo.
echo After your confirmation the script will stop and the console may be closed.
pause