-
Notifications
You must be signed in to change notification settings - Fork 3
/
start_windows.bat
78 lines (71 loc) · 2.42 KB
/
start_windows.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
@echo off
:: Redirect errors to a log file
set LOGFILE=script_log.txt
echo Logging errors to %LOGFILE%
echo If you run this script for the first time, it may take some time.
echo ------------------------------------------------------------------
:: Check if Python is installed
where python >nul 2>nul || (
echo Python is not installed. Please install Python 3.6+ to continue.
echo %date% %time% - Python not installed >> %LOGFILE%
pause
exit /b 1
)
:: Check if virtual environment exists
if exist venv\Scripts\activate (
echo Virtual environment already exists. Skipping creation.
) else (
echo Creating virtual environment...
python -m venv venv >> %LOGFILE% 2>&1
if %ERRORLEVEL% NEQ 0 (
echo Failed to create virtual environment. Make sure Python 3.6+ is properly installed.
echo %date% %time% - Failed to create virtual environment >> %LOGFILE%
pause
exit /b 1
)
)
:: Activate the virtual environment
echo Activating virtual environment...
call venv\Scripts\activate >> %LOGFILE% 2>&1
if %ERRORLEVEL% NEQ 0 (
echo Failed to activate the virtual environment.
echo %date% %time% - Failed to activate the virtual environment >> %LOGFILE%
pause
exit /b 1
)
:: Upgrade pip with the correct command
echo Upgrading pip...
python -m pip install --upgrade pip >> %LOGFILE% 2>&1
if %ERRORLEVEL% NEQ 0 (
echo Failed to upgrade pip. Please check your Python and pip installation.
echo %date% %time% - Failed to upgrade pip >> %LOGFILE%
pause
exit /b 1
)
:: Check and install requirements
echo Checking installed packages...
pip list --format=freeze > installed_packages.txt
findstr /V /G:installed_packages.txt requirements.txt > missing_packages.txt
if exist missing_packages.txt (
echo Installing missing requirements... Please wait!
pip install -r requirements.txt >> %LOGFILE% 2>&1
if %ERRORLEVEL% NEQ 0 (
echo Failed to install some dependencies. Please check the requirements file.
echo %date% %time% - Failed to install dependencies >> %LOGFILE%
pause
exit /b 1
)
) else (
echo All requirements are already installed.
)
:: Run the main script
echo Running main.py...
python main.py
if %ERRORLEVEL% NEQ 0 (
echo An error occurred while running main.py. Please check the script for errors.
echo %date% %time% - Error running main.py >> %LOGFILE%
pause
exit /b 1
)
echo Script executed successfully!
pause