install.bat 3.2 KB

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