diff --git a/gui-uv.bat b/gui-uv.bat index 22920f9..464eaac 100644 --- a/gui-uv.bat +++ b/gui-uv.bat @@ -16,21 +16,41 @@ if %errorlevel% neq 0 ( ) endlocal +echo Ensuring virtual environment .venv is set up... +uv venv .venv +if errorlevel 1 ( + echo Failed to create or set up the virtual environment. Exiting. + exit /b 1 +) + +:: Ensures PyTorch native libraries (DLLs) are found set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib echo Starting the GUI... this might take some time... Especially on 1st run after install or update... :: Make sure we are on the right sd-scripts commit git submodule update --init --recursive +if errorlevel 1 ( + echo Error updating git submodules. Please check for errors and try again. + exit /b 1 +) -:: If the exit code is 0, run the kohya_gui.py script with the command-line arguments -if %errorlevel% equ 0 ( - REM Check if the batch was started via double-click - IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" ( - REM echo This script was started by double clicking. - cmd /k uv run --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %* - ) ELSE ( - REM echo This script was started from a command prompt. - uv run --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %* +:: If we reach here, git submodules updated successfully. +set "uv_quiet_arg=" +for %%a in (%*) do ( + if /i "%%a"=="--quiet" ( + set "uv_quiet_arg=--quiet" ) -) \ No newline at end of file +) + +REM Check if the script was started by double-clicking (interactive session) +REM or from an existing command prompt. +REM If double-clicked, use 'cmd /k' to keep the window open after uv run finishes or errors. +REM Check if the batch was started via double-click +IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" ( + REM echo This script was started by double clicking. + cmd /k uv run %uv_quiet_arg% --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %* +) ELSE ( + REM echo This script was started from a command prompt. + uv run %uv_quiet_arg% --link-mode=copy --index-strategy unsafe-best-match kohya_gui.py --noverify %* +) diff --git a/gui-uv.sh b/gui-uv.sh index c6436d1..9512d98 100755 --- a/gui-uv.sh +++ b/gui-uv.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e export VIRTUAL_ENV=.venv env_var_exists() { @@ -9,6 +10,8 @@ env_var_exists() { fi } +# Handle LD_LIBRARY_PATH for WSL environments and preserve it when using sudo, +# as these can affect how shared libraries are found. lib_path="/usr/lib/wsl/lib/" if [ -d "$lib_path" ]; then @@ -47,9 +50,12 @@ if ! command -v uv &> /dev/null; then fi fi +echo "Ensuring virtual environment .venv is set up..." +uv venv .venv || { echo "Failed to create or set up the virtual environment. Exiting."; exit 1; } + if [[ "$uv_quiet" == "--quiet" ]]; then echo "Notice: uv will run in quiet mode. No indication of the uv module download and install process will be displayed." fi -git submodule update --init --recursive +git submodule update --init --recursive || { echo "ERROR: Failed to update git submodules. Please check for errors above and try again." >&2; exit 1; } uv run $uv_quiet kohya_gui.py --noverify "${args[@]}" diff --git a/pyproject.toml b/pyproject.toml index 2d15a42..52846dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,18 +54,9 @@ dependencies = [ ] [tool.uv.sources] -torch = [ - { index = "pytorch-cu128", marker = "sys_platform == 'linux'" }, - { index = "pytorch-cu128", marker = "sys_platform == 'win32'" } -] -torchvision = [ - { index = "pytorch-cu128", marker = "sys_platform == 'linux'" }, - { index = "pytorch-cu128", marker = "sys_platform == 'win32'" } -] -xformers = [ - { index = "pytorch-cu128", marker = "sys_platform == 'linux'" }, - { index = "pytorch-cu128", marker = "sys_platform == 'win32'" } -] +torch = { index = "pytorch-cu128" } +torchvision = { index = "pytorch-cu128" } +xformers = { index = "pytorch-cu128" } library = { path = "sd-scripts" } [[tool.uv.index]]