install_env.bat 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. @echo off
  2. chcp 65001
  3. set USE_MIRROR=true
  4. echo use_mirror = %USE_MIRROR%
  5. setlocal enabledelayedexpansion
  6. cd /D "%~dp0"
  7. set PATH="%PATH%";%SystemRoot%\system32
  8. echo %PATH%
  9. echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~\u4E00-\u9FFF ] " >nul && (
  10. echo.
  11. echo There are special characters in the current path, please make the path of fish-speech free of special characters before running. && (
  12. goto end
  13. )
  14. )
  15. set TMP=%CD%\fishenv
  16. set TEMP=%CD%\fishenv
  17. (call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
  18. set INSTALL_DIR=%cd%\fishenv
  19. set CONDA_ROOT_PREFIX=%cd%\fishenv\conda
  20. set INSTALL_ENV_DIR=%cd%\fishenv\env
  21. set PIP_CMD=%cd%\fishenv\env\python -m pip
  22. set PYTHON_CMD=%cd%\fishenv\env\python
  23. set API_FLAG_PATH=%~dp0API_FLAGS.txt
  24. set MINICONDA_DOWNLOAD_URL=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
  25. set MINICONDA_CHECKSUM=307194e1f12bbeb52b083634e89cc67db4f7980bd542254b43d3309eaf7cb358
  26. set conda_exists=F
  27. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
  28. if "%ERRORLEVEL%" EQU "0" set conda_exists=T
  29. if "%conda_exists%" == "F" (
  30. echo.
  31. echo Downloading Miniconda...
  32. mkdir "%INSTALL_DIR%" 2>nul
  33. call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe"
  34. if errorlevel 1 (
  35. echo.
  36. echo Failed to download miniconda.
  37. goto end
  38. )
  39. for /f %%a in ('
  40. certutil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" sha256
  41. ^| find /i /v " "
  42. ^| find /i "%MINICONDA_CHECKSUM%"
  43. ') do (
  44. set "hash=%%a"
  45. )
  46. if not defined hash (
  47. echo.
  48. echo Miniconda hash mismatched!
  49. del "%INSTALL_DIR%\miniconda_installer.exe"
  50. goto end
  51. ) else (
  52. echo.
  53. echo Miniconda hash matched successfully.
  54. )
  55. echo Downloaded "%CONDA_ROOT_PREFIX%"
  56. start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%
  57. call "%CONDA_ROOT_PREFIX%\_conda.exe" --version
  58. if errorlevel 1 (
  59. echo.
  60. echo Cannot install Miniconda.
  61. goto end
  62. ) else (
  63. echo.
  64. echo Miniconda Install success.
  65. )
  66. del "%INSTALL_DIR%\miniconda_installer.exe"
  67. )
  68. if not exist "%INSTALL_ENV_DIR%" (
  69. echo.
  70. echo Creating Conda Environment...
  71. call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ python=3.10
  72. if errorlevel 1 (
  73. echo.
  74. echo Failed to Create Environment.
  75. goto end
  76. )
  77. )
  78. if not exist "%INSTALL_ENV_DIR%\python.exe" (
  79. echo.
  80. echo Conda Env does not exist.
  81. goto end
  82. )
  83. set PYTHONNOUSERSITE=1
  84. set PYTHONPATH=
  85. set PYTHONHOME=
  86. set "CUDA_PATH=%INSTALL_ENV_DIR%"
  87. set "CUDA_HOME=%CUDA_PATH%"
  88. call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%"
  89. if errorlevel 1 (
  90. echo.
  91. echo Failed to activate Env.
  92. goto end
  93. ) else (
  94. echo.
  95. echo successfully create env.
  96. )
  97. set "packages=torch torchvision torchaudio openai-whisper fish-speech"
  98. set "install_packages="
  99. for %%p in (%packages%) do (
  100. %PIP_CMD% show %%p >nul 2>&1
  101. if errorlevel 1 (
  102. set "install_packages=!install_packages! %%p"
  103. )
  104. )
  105. if not "!install_packages!"=="" (
  106. echo.
  107. echo Installing: !install_packages!
  108. for %%p in (!install_packages!) do (
  109. if "!USE_MIRROR!"=="true" (
  110. if "%%p"=="torch" (
  111. %PIP_CMD% install torch --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  112. ) else if "%%p"=="torchvision" (
  113. %PIP_CMD% install torchvision --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  114. ) else if "%%p"=="torchaudio" (
  115. %PIP_CMD% install torchaudio --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
  116. ) else if "%%p"=="openai-whisper" (
  117. %PIP_CMD% install -i https://pypi.tuna.tsinghua.edu.cn/simple openai-whisper --no-warn-script-location
  118. ) else if "%%p"=="fish-speech" (
  119. %PIP_CMD% install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
  120. )
  121. ) else (
  122. if "%%p"=="torch" (
  123. %PIP_CMD% install torch --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  124. ) else if "%%p"=="torchvision" (
  125. %PIP_CMD% install torchvision --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  126. ) else if "%%p"=="torchaudio" (
  127. %PIP_CMD% install torchaudio --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
  128. ) else if "%%p"=="openai-whisper" (
  129. %PIP_CMD% install openai-whisper --no-warn-script-location
  130. ) else if "%%p"=="fish-speech" (
  131. %PIP_CMD% install -e .
  132. )
  133. )
  134. )
  135. )
  136. echo Environment Check: Success.
  137. endlocal
  138. pause