MiDaS icon indicating copy to clipboard operation
MiDaS copied to clipboard

PyTorch Hub ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package

Open xvel opened this issue 3 years ago • 6 comments

Can't download model

model = torch.hub.load("intel-isl/MiDaS", "DPT_Large")

gives this on Windows 10, Anaconda env, Pytorch 1.9, Pycharm IDE

Traceback (most recent call last):
  File "C:/Users/abcd/PycharmProjects/test/midas.py", line 12, in <module>
    midas_v3L = torch.hub.load("intel-isl/MiDaS", model_type)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 390, in _load_local
    hub_module = import_module(MODULE_HUBCONF, hubconf_path)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 75, in import_module
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\abcd/.cache\torch\hub\intel-isl_MiDaS_master\hubconf.py", line 5, in <module>
    from midas.dpt_depth import DPTDepthModel
  File "C:\Users\abcd\PycharmProjects\test\midas.py", line 12, in <module>
    midas_v3L = torch.hub.load("intel-isl/MiDaS", model_type)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 390, in _load_local
    hub_module = import_module(MODULE_HUBCONF, hubconf_path)
  File "C:\Users\abcd\anaconda3\envs\pytorchenv\lib\site-packages\torch\hub.py", line 75, in import_module
    spec.loader.exec_module(module)
  File "C:\Users\abcd/.cache\torch\hub\intel-isl_MiDaS_master\hubconf.py", line 5, in <module>
    from midas.dpt_depth import DPTDepthModel
ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package

xvel avatar Jun 26 '21 23:06 xvel

This seems unrelated to MiDaS. I believe you might have naming conflict with some file shadowing the MiDaS namespace. See here: https://stackoverflow.com/questions/59502364/modulenotfounderror-no-module-named-xxx-xxx-is-not-a-package

ranftlr avatar Jun 28 '21 13:06 ranftlr

u can change this import code ,like this

# from midas.dpt_depth import DPTDepthModel
from MiDaS.midas.dpt_depth import DPTDepthModel
# from midas.midas_net import MidasNet
from MiDaS.midas.midas_net import MidasNet
# from midas.midas_net_custom import MidasNet_small
from MiDaS.midas.midas_net_custom import MidasNet_small
# from midas.transforms import Resize, NormalizeImage, PrepareForNet
from MiDaS.midas.transforms import Resize, NormalizeImage, PrepareForNet

this use path to find class name and import it

LeXwDeX avatar Jun 03 '22 13:06 LeXwDeX

This seems unrelated to MiDaS. I believe you might have naming conflict with some file shadowing the MiDaS namespace. See here: https://stackoverflow.com/questions/59502364/modulenotfounderror-no-module-named-xxx-xxx-is-not-a-package

Right, this is unrelated with MiDaS. Was parent folder was named midas and my file midas.py, I renamed both and now it works (maybe only one has to be renamed)

remmel avatar Jul 01 '22 10:07 remmel

I have fixed this error with pip install timm

andylucny avatar Jul 27 '22 07:07 andylucny

ModuleNotFoundError: No module named 'midas.dpt_depth'; 'midas' is not a package This error pops up again, I have timm, and the midas model is in a ComfyUI directory, unsure what installed it. I've searched for potentially shadowing variables, but none of the midas variables seemed to be the culprit. What helps for me is placing an (empty) __init__.py in the ComfyUI/models/midas/intel-isl_MiDaS_master/midas directory.

picobyte avatar Nov 12 '23 17:11 picobyte

if you tried "pip install midas" before thinking it was correct thats whats causing the issue. #2023

pip uninstall midas, pip install timm

and that should fix it all.

kennydd001 avatar Jan 07 '24 19:01 kennydd001