thygate / stable-diffusion-webui-depthmap-script

High Resolution Depth Maps for Stable Diffusion WebUI
MIT License
1.7k stars 160 forks source link

ModuleNotFoundError: No module named 'midas' #128

Open Mozoloa opened 1 year ago

Mozoloa commented 1 year ago

Hello!

I've just installed this extension via URL in an updated perfectly functioning A1111 install and the script won't load.

At launch I get ModuleNotFoundError: No module named 'midas'

More info:

Launching Web UI with arguments: --autolaunch --xformers --ckpt-dir C:\AI\Models\Stable-diffusion --vae-path C:\AI\Models\Stable-diffusion\NewVAE.vae.pt --embeddings-dir C:\AI\Models\Embeddings
Error loading script: depthmap.py
Traceback (most recent call last):
  File "D:\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\modules\scripts.py", line 229, in load_scripts
    script_module = script_loading.load_module(scriptfile.path)
  File "D:\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\modules\script_loading.py", line 11, in load_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Documents\A1111 Web UI Autoinstaller\stable-diffusion-webui\extensions\Depth\scripts\depthmap.py", line 40, in <module>
    from midas.dpt_depth import DPTDepthModel
ModuleNotFoundError: No module named 'midas'

I've tried deleting venv, and it's still doing it

Itelmen commented 1 year ago

Just rename the script folder from "DepthMap" to "stable-diffusion-webui-depthmap-script". This is in "stable-diffusion-webui\extensions\"

Mozoloa commented 1 year ago

This worked ! That's odd that the folder was renamed that way and it broke things

Xyem commented 1 year ago

Of the 36 extensions I have installed, only this one and sd_smartprocess seem to be sensitive to the name of their directory.

In this case, I suspect it is because it is hard-coded here: https://github.com/thygate/stable-diffusion-webui-depthmap-script/blob/main/scripts/depthmap.py#L37

Mozoloa commented 1 year ago

Of the 36 extensions I have installed, only this one and sd_smartprocess seem to be sensitive to the name of their directory.

In this case, I suspect it is because it is hard-coded here: https://github.com/thygate/stable-diffusion-webui-depthmap-script/blob/main/scripts/depthmap.py#L37

And that's exactly one line above the error, good find

Xyem commented 1 year ago

Replacing that line with the following appears to work:

import pathlib
path_append = pathlib.Path(__file__).parent.resolve()
sys.path.append(str(path_append))
Xyem commented 1 year ago

In case it isn't clear why this happens, the extension adds its own scripts directory as a path to find modules in (e.g. the midas one in this instance), but it does so by adding a relative path from the webui's root to the searched paths.

The above changes gets the current script path, takes the parent (i.e. scripts directory) and then adds that instead, so the extensions directory name is no longer hard-coded into the relative path.

thygate commented 1 year ago

Replacing that line with the following appears to work:

import pathlib
path_append = pathlib.Path(__file__).parent.resolve()
sys.path.append(str(path_append))

will change in next version