diff --git a/monai/utils/module.py b/monai/utils/module.py index 251232d62f..1ac8140b39 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -13,7 +13,6 @@ import enum import functools -import importlib.util import os import pdb import re @@ -209,11 +208,13 @@ def load_submodules( ): if (is_pkg or load_all) and name not in sys.modules and match(exclude_pattern, name) is None: try: + mod = import_module(name) mod_spec = importer.find_spec(name) # type: ignore if mod_spec and mod_spec.loader: - mod = importlib.util.module_from_spec(mod_spec) - mod_spec.loader.exec_module(mod) + loader = mod_spec.loader + loader.exec_module(mod) submodules.append(mod) + except OptionalImportError: pass # could not import the optional deps., they are ignored except ImportError as e: