Skip to content

Support Python 3.12 #7491

Closed
Closed
@ziw-liu

Description

@ziw-liu

Describe the bug
MONAI does not work with Python 3.12 since it uses the deprecated (and now removed) find_module API from importlib. See Python release note.

To Reproduce

Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:36:57) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import monai
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/Caskroom/miniforge/base/envs/p312/lib/python3.12/site-packages/monai/__init__.py", line 58, in <module>
    load_submodules(sys.modules[__name__], False, exclude_pattern=excludes)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/p312/lib/python3.12/site-packages/monai/utils/module.py", line 212, in load_submodules
    importer.find_module(name).load_module(name)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'FileFinder' object has no attribute 'find_module'

Expected behavior
This was previously put on hold in #7096 due to torch not supporting 3.12. Since torch now has Python 3.12 support in v2.2.1, MONAI should work as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions