arenasys/sd-tagging-helper

a simple fix to DDB installing problem caused by python version

Opened this issue · 0 comments

This solution target to DDB installing problems similar to #20 :
In your sd-tagging-helper root directory/crash.log, there maybe something like this:

ImportError: Failed to load PyTorch C extensions:
    It appears that PyTorch has loaded the `torch/_C` folder
    of the PyTorch repository rather than the C extensions which
    are expected in the `torch._C` namespace. This can occur when
    using the `install` workflow. e.g.
        $ python setup.py install && python -c "import torch"

    This error can generally be solved using the `develop` workflow
        $ python setup.py develop && python -c "import torch"  # This should succeed
    or by running Python from a different directory.

Then it maybe caused by the venv initialized by a wrong python version due to your system path variables settings.
And I came up with an idea that 'If our DDB rely on WebUI, why not using its venv to initialize ours instead?', and I wrote a batch named venv_fix.bat with the following content:

<!-- : batch
@echo off
setlocal

for /f "delims=" %%n in ('cscript //nologo "%~f0?.wsf"') do (
  set webui_folder_path=%%n
)

if not "%webui_folder_path%" == "" goto :init
echo Selection cancelled.
pause
exit

:init

call "%webui_folder_path%\venv\Scripts\activate.bat" /S

echo Selected WebUI path: %webui_folder_path%
echo Try activate WebUI's venv from %webui_folder_path%\venv\Scripts\activate.bat ...
echo.
if exist .\venv\ (  
  echo Attention! sd-tagging-helper's venv already exists
  echo.
  echo Continue? This will COMPLETELY REMOVE sd-tagging-helper's existing venv and RECREATE it!
  echo.
  pause
  echo Removing...
  rd .\venv\ /s /q
  echo Removed.
  echo.  
)

echo Initializing venv...
mkdir venv
  python -m venv .\venv\
start /wait /b "" .\venv\Scripts\pip3.exe install -q pillow pyqt5==5.15.7

echo Done.
echo.
pause
endlocal
-- wsf used to popup folder select window -->

<job>
  <script language="VBScript">
    set obj_shell = CreateObject("Shell.Application")
    set obj_folder = obj_shell.BrowseForFolder(0, "Select your WebUI's folder", 0, "C:\")
    if (not obj_folder is nothing) Then
      WScript.Echo obj_folder.Self.Path
    end if
  </script>
</job>

It popup a folder selector dialog to prompt user choose the WebUI's directory, activate its venv and using it to initial ours venv.
Tested on my Win10 machine, and fixed the problem.
But I'm not sure if there's a problem I haven't found, so rather than PR, I initiated an issue to get some opinion...