Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module can not import correctly issue #8015

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions monai/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import enum
import functools
import importlib.util
import os
import pdb
import re
Expand Down Expand Up @@ -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:
Expand Down
Loading