From 40a9be6c94b7ceef60152e1115973f6a8c328f2c Mon Sep 17 00:00:00 2001 From: bmaltais Date: Sun, 10 Mar 2024 19:07:22 -0400 Subject: [PATCH 1/4] Add more validation for the Python version. Will now stop if the wrong version is detected --- gui.bat | 1 + gui.ps1 | 6 ++++++ gui.sh | 3 +++ setup/setup_common.py | 22 +++++++++++++--------- setup/validate_requirements.py | 7 ++++--- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gui.bat b/gui.bat index 1afbaead5..4f79e7dea 100644 --- a/gui.bat +++ b/gui.bat @@ -17,6 +17,7 @@ set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib :: Validate requirements python.exe .\setup\validate_requirements.py +if %errorlevel% neq 0 exit /b %errorlevel% :: If the exit code is 0, run the kohya_gui.py script with the command-line arguments if %errorlevel% equ 0 ( diff --git a/gui.ps1 b/gui.ps1 index 1ef3932f0..be9796ca8 100644 --- a/gui.ps1 +++ b/gui.ps1 @@ -34,6 +34,12 @@ $env:PATH += ";$($MyInvocation.MyCommand.Path)\venv\Lib\site-packages\torch\lib" # Validate the requirements and store the exit code python.exe .\setup\validate_requirements.py +# Check the exit code and stop execution if it is not 0 +if ($LASTEXITCODE -ne 0) { + Write-Host "Failed to validate requirements. Exiting script..." + exit $LASTEXITCODE +} + # If the exit code is 0, read arguments from gui_parameters.txt (if it exists) # and run the kohya_gui.py script with the command-line arguments if ($LASTEXITCODE -eq 0) { diff --git a/gui.sh b/gui.sh index 50704dbc8..1d6e5547b 100755 --- a/gui.sh +++ b/gui.sh @@ -109,4 +109,7 @@ fi # Validate the requirements and run the script if successful if python "$SCRIPT_DIR/setup/validate_requirements.py" -r "$REQUIREMENTS_FILE"; then "${STARTUP_CMD}" $STARTUP_CMD_ARGS "$SCRIPT_DIR/kohya_gui.py" "$@" +else + echo "Validation failed. Exiting..." + exit 1 fi diff --git a/setup/setup_common.py b/setup/setup_common.py index d4dbf8108..23456cb5b 100644 --- a/setup/setup_common.py +++ b/setup/setup_common.py @@ -18,21 +18,25 @@ def check_python_version(): """ Check if the current Python version is >= 3.10.9 and < 3.11.0 - + Returns: bool: True if the current Python version is valid, False otherwise. """ min_version = (3, 10, 9) max_version = (3, 11, 0) - current_version = sys.version_info - - log.info(f"Python version is {sys.version}") - if not (min_version <= current_version < max_version): - log.error(f"The current version of python is not appropriate to run Kohya_ss GUI") - log.error("The python version need to be greater or equal to 3.10.9 and less than 3.11.0") - - return (min_version <= current_version < max_version) + try: + current_version = sys.version_info + log.info(f"Python version is {sys.version}") + + if not (min_version <= current_version < max_version): + log.error("The current version of python is not appropriate to run Kohya_ss GUI") + log.error("The python version needs to be greater or equal to 3.10.9 and less than 3.11.0") + return False + return True + except Exception as e: + log.error(f"Failed to verify Python version. Error: {e}") + return False def update_submodule(): """ diff --git a/setup/validate_requirements.py b/setup/validate_requirements.py index ee924a757..f7566847b 100644 --- a/setup/validate_requirements.py +++ b/setup/validate_requirements.py @@ -102,12 +102,13 @@ def main(): ) parser.add_argument('--debug', action='store_true', help='Debug on') args = parser.parse_args() + + setup_common.update_submodule() torch_ver = check_torch() - python_ver = setup_common.check_python_version() - - setup_common.update_submodule() + if not setup_common.check_python_version(): + exit(1) if args.requirements: setup_common.install_requirements(args.requirements, check_no_verify_flag=True) From 8e61677b7ff410e77979e7e9c2fb98ca12f0b426 Mon Sep 17 00:00:00 2001 From: Bernard Maltais Date: Sun, 10 Mar 2024 19:20:57 -0400 Subject: [PATCH 2/4] Install missing packaging module --- gui.bat | 3 +++ gui.ps1 | 2 ++ setup.sh | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/gui.bat b/gui.bat index 4f79e7dea..c47c30d5a 100644 --- a/gui.bat +++ b/gui.bat @@ -15,6 +15,9 @@ if errorlevel 1 ( call .\venv\Scripts\activate.bat set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib +echo "Installing packaging python module..." +pip install packaging + :: Validate requirements python.exe .\setup\validate_requirements.py if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/gui.ps1 b/gui.ps1 index be9796ca8..5ab233d60 100644 --- a/gui.ps1 +++ b/gui.ps1 @@ -28,6 +28,8 @@ if ($env:VIRTUAL_ENV) { & .\venv\Scripts\activate $env:PATH += ";$($MyInvocation.MyCommand.Path)\venv\Lib\site-packages\torch\lib" +Write-Host "Installing python packaging module..." +& pip install packaging # Debug info about system # python.exe .\setup\debug_info.py diff --git a/setup.sh b/setup.sh index 5cb6a4e83..015d34e55 100755 --- a/setup.sh +++ b/setup.sh @@ -201,6 +201,10 @@ install_python_dependencies() { source "$DIR/venv/bin/activate" fi + # Install packaging + echo "Installing the python packaging module..." + pip install packaging + case "$OSTYPE" in "lin"*) if [ "$RUNPOD" = true ]; then From 1b0a679833a9a53205db8d14d733c357b679cc72 Mon Sep 17 00:00:00 2001 From: Bernard Maltais Date: Sun, 10 Mar 2024 19:24:44 -0400 Subject: [PATCH 3/4] Fix typo in setup.sh --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 015d34e55..70db7a167 100755 --- a/setup.sh +++ b/setup.sh @@ -629,5 +629,5 @@ elif [[ "$OSTYPE" == "cygwin" ]]; then elif [[ "$OSTYPE" == "msys" ]]; then # MinGW has the msys environment which is a standalone suite of Linux utilities on Windows # "git bash" on Windows may also be detected as msys. - echo "This hasn't been validated in msys (mingw) on Windows yet." + echo "This hasn't been validated in msys 'mingw' on Windows yet." fi From 5fa3876ab8f37a0c8cf520891cf503ea1e6cfedc Mon Sep 17 00:00:00 2001 From: bmaltais Date: Sun, 10 Mar 2024 19:30:06 -0400 Subject: [PATCH 4/4] Update setup --- .release | 2 +- README.md | 6 ++++++ gui.bat | 3 --- gui.ps1 | 2 -- setup.bat | 3 +++ setup.ps1 | 5 ++++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.release b/.release index 56a37ffda..109b640bc 100644 --- a/.release +++ b/.release @@ -1 +1 @@ -v23.0.2 \ No newline at end of file +v23.0.3 \ No newline at end of file diff --git a/README.md b/README.md index 08d1ed99b..1094b546c 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ The GUI allows you to set the training parameters and generate and run the requi - [No module called tkinter](#no-module-called-tkinter) - [SDXL training](#sdxl-training) - [Change History](#change-history) + - [2024/03/10 (v23.0.3)](#20240310-v2303) - [2024/03/10 (v23.0.2)](#20240310-v2302) - [2024/03/09 (v23.0.1)](#20240309-v2301) - [2024/03/02 (v23.0.0)](#20240302-v2300) @@ -365,6 +366,11 @@ The documentation in this section will be moved to a separate document later. ## Change History +### 2024/03/10 (v23.0.3) + +- Fix bug with setup +- Enforce proper python version before running the GUI to prevent issues with execution of the GUI. + ### 2024/03/10 (v23.0.2) - Improve validation of path provided by users before running training diff --git a/gui.bat b/gui.bat index c47c30d5a..4f79e7dea 100644 --- a/gui.bat +++ b/gui.bat @@ -15,9 +15,6 @@ if errorlevel 1 ( call .\venv\Scripts\activate.bat set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib -echo "Installing packaging python module..." -pip install packaging - :: Validate requirements python.exe .\setup\validate_requirements.py if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/gui.ps1 b/gui.ps1 index 5ab233d60..be9796ca8 100644 --- a/gui.ps1 +++ b/gui.ps1 @@ -28,8 +28,6 @@ if ($env:VIRTUAL_ENV) { & .\venv\Scripts\activate $env:PATH += ";$($MyInvocation.MyCommand.Path)\venv\Lib\site-packages\torch\lib" -Write-Host "Installing python packaging module..." -& pip install packaging # Debug info about system # python.exe .\setup\debug_info.py diff --git a/setup.bat b/setup.bat index 7d1cc70f1..79ff65cc3 100644 --- a/setup.bat +++ b/setup.bat @@ -24,6 +24,9 @@ call .\venv\Scripts\deactivate.bat call .\venv\Scripts\activate.bat +echo "Installing packaging python module..." +pip install packaging + 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. diff --git a/setup.ps1 b/setup.ps1 index df5f92e68..5459b5fb1 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -17,10 +17,13 @@ $null = New-Item -ItemType Directory -Force -Path ".\logs\setup" & .\venv\Scripts\deactivate.bat # Calling external python program to check for local modules -& .\venv\Scripts\python.exe .\setup\check_local_modules.py +# & .\venv\Scripts\python.exe .\setup\check_local_modules.py & .\venv\Scripts\activate.bat +Write-Host "Installing python packaging module..." +& pip install packaging + & .\venv\Scripts\python.exe .\setup\setup_windows.py # Deactivate the virtual environment