install.bat 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. @echo off
  2. REM ==========================================================
  3. REM MRI physics based augmentation - Windows one-click setup
  4. REM - Installs Python 3.12.10 via winget (if missing)
  5. REM - Creates venv .venv
  6. REM - Installs requirements
  7. REM - Runs Streamlit app
  8. REM No PowerShell required.
  9. REM ==========================================================
  10. SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  11. SET PY_REQ_VER=3.12
  12. SET PY_FULL_VER=3.12.10
  13. SET APP_PORT=8501
  14. ECHO.
  15. ECHO [INFO] Working directory: %CD%
  16. REM --- Step 1: Check Python 3.12 availability ---
  17. SET "PYCMD="
  18. py -%PY_REQ_VER% -V >NUL 2>&1
  19. IF %ERRORLEVEL%==0 (
  20. SET "PYCMD=py -%PY_REQ_VER%"
  21. ) ELSE (
  22. FOR /F "tokens=2 delims= " %%v IN ('python -V 2^>NUL') DO SET "PYV=%%v"
  23. ECHO !PYV! | FINDSTR /B "%PY_REQ_VER%" >NUL 2>&1
  24. IF !ERRORLEVEL!==0 SET "PYCMD=python"
  25. )
  26. IF "%PYCMD%"=="" (
  27. ECHO [WARN] Python %PY_REQ_VER% not found. Trying to install %PY_FULL_VER% via winget...
  28. winget --version >NUL 2>&1
  29. IF ERRORLEVEL 1 (
  30. ECHO [ERROR] winget is not available. Please install Python %PY_FULL_VER% from:
  31. ECHO https://www.python.org/downloads/windows/
  32. ECHO Then re-run this script.
  33. PAUSE
  34. EXIT /B 1
  35. )
  36. winget install -e --id Python.Python.3.12 --version %PY_FULL_VER% --scope user --silent
  37. IF ERRORLEVEL 1 (
  38. ECHO [ERROR] winget failed to install Python %PY_FULL_VER%. Install manually and re-run.
  39. PAUSE
  40. EXIT /B 1
  41. )
  42. REM Try again after install
  43. py -%PY_REQ_VER% -V >NUL 2>&1 && SET "PYCMD=py -%PY_REQ_VER%"
  44. IF "%PYCMD%"=="" (
  45. python -V 2>NUL | FIND "Python %PY_REQ_VER%" >NUL && SET "PYCMD=python"
  46. )
  47. )
  48. IF "%PYCMD%"=="" (
  49. ECHO [ERROR] Python %PY_REQ_VER% still not available in PATH. Close/reopen this window and run again.
  50. PAUSE
  51. EXIT /B 1
  52. ) ELSE (
  53. ECHO [INFO] Using Python command: %PYCMD%
  54. )
  55. REM --- Step 2: Create virtual environment ---
  56. IF NOT EXIST .venv (
  57. ECHO [INFO] Creating virtual environment (.venv)
  58. %PYCMD% -m venv .venv
  59. IF ERRORLEVEL 1 (
  60. ECHO [ERROR] Failed to create virtual environment.
  61. PAUSE
  62. EXIT /B 1
  63. )
  64. ) ELSE (
  65. ECHO [INFO] Virtual environment already exists (.venv)
  66. )
  67. REM --- Step 3: Activate venv ---
  68. IF NOT EXIST .venv\Scripts\activate.bat (
  69. ECHO [ERROR] Activation script not found: .venv\Scripts\activate.bat
  70. PAUSE
  71. EXIT /B 1
  72. )
  73. CALL .venv\Scripts\activate
  74. REM --- Step 4: Ensure requirements.txt ---
  75. IF NOT EXIST requirements.txt (
  76. ECHO [INFO] Creating requirements.txt
  77. > requirements.txt ECHO streamlit==1.37.0
  78. >>requirements.txt ECHO pillow>=10.3.0
  79. >>requirements.txt ECHO numpy>=1.26.4
  80. >>requirements.txt ECHO pydicom>=2.4.4
  81. >>requirements.txt ECHO nibabel>=5.2.1
  82. )
  83. REM --- Step 5: Upgrade pip and install deps ---
  84. python -m pip install --upgrade pip
  85. IF ERRORLEVEL 1 ECHO [WARN] pip upgrade failed, continuing...
  86. pip install -r requirements.txt
  87. IF ERRORLEVEL 1 (
  88. ECHO [ERROR] Failed to install dependencies from requirements.txt
  89. PAUSE
  90. EXIT /B 1
  91. )
  92. REM --- Step 6: Create assets folder (optional) ---
  93. IF NOT EXIST assets (
  94. ECHO [INFO] Creating assets folder
  95. mkdir assets >NUL 2>&1
  96. )
  97. REM --- Step 7: Run the app ---
  98. ECHO.
  99. ECHO [INFO] Launching app on port %APP_PORT% ...
  100. streamlit run app.py --server.port %APP_PORT% --server.address 127.0.0.1
  101. ECHO.
  102. ECHO [INFO] Streamlit exited. Press any key to close this window.
  103. PAUSE