-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStart.bat
91 lines (69 loc) · 1.93 KB
/
Start.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@echo off
setlocal enabledelayedexpansion
REM Set up a Python virtual environment and run a specified Python script.
REM Variables
set "PYTHON_SCRIPT=img-txt_viewer.py"
set "VENV_DIR=venv"
set "SCRIPT_DIR=%~dp0"
REM Navigate to the script directory
cd /d "%SCRIPT_DIR%" || (
echo Failed to set current directory.
pause
exit /b 1
)
echo Set current directory... OK
REM Check if Python is installed
python --version >nul 2>&1 || (
echo Python is not installed or not found in PATH.
pause
exit /b 1
)
REM Check if the virtual environment already exists
if not exist "%VENV_DIR%\Scripts\activate.bat" (
echo Creating a Python virtual environment: "%SCRIPT_DIR%\%VENV_DIR%"
python -m venv "%VENV_DIR%" || (
echo An error occurred while creating the virtual environment.
pause
exit /b 1
)
echo Virtual environment created.
) else (
echo Virtual environment already exists: "%SCRIPT_DIR%\%VENV_DIR%"
)
REM Activate the virtual environment
call "%VENV_DIR%\Scripts\activate.bat" || (
echo Activating the virtual environment... FAIL
pause
exit /b 1
)
echo Virtual environment activated.
REM Upgrade pip
python -m pip install --upgrade pip
REM Install requirements if requirements.txt exists
if exist "requirements.txt" (
set /p INSTALL_REQ="requirements.txt found. Do you want to install the requirements? (Y/N): "
if /i "!INSTALL_REQ!"=="Y" (
echo Installing requirements...
pip install -r requirements.txt || (
echo Failed to install requirements.
pause
exit /b 1
)
) else (
echo Skipping requirements installation.
)
)
REM Launch the user-defined Python script
if "%PYTHON_SCRIPT%"=="" (
echo Auto-Launch: Skipping
) else (
echo Launching: %PYTHON_SCRIPT%
python "%PYTHON_SCRIPT%" || (
echo Launching... FAIL
pause
exit /b 1
)
)
echo.
call cmd /k
endlocal