Repository: Project-MONAI/MONAI

Issue:
Python 3.12 import AttributeError: 'FileFinder' object has no attribute 'find_module'
**Describe the bug**
When installing monai (via pip) into a conda environment of python 3.12.1, I get a 
"
AttributeError: 'FileFinder' object has no attribute 'find_module'
"
as soon as i call "import monai"

**To Reproduce**
Steps to reproduce the behavior:
1. conda create --name test python=3.12
2. conda activate test
3. pip install monai
4. python
5. import monai
-> see screenshot below


**Expected behavior**
I should be able to import monai

**Screenshots**
installing monai triggered a lot of other package installations: 
![Screenshot from 2024-02-09 13-06-58](https://github.com/Project-MONAI/MONAI/assets/19862882/71118752-d811-4034-af86-1c0eb70a625a)

![Screenshot from 2024-02-09 13-03-27](https://github.com/Project-MONAI/MONAI/assets/19862882/7b505ba6-1501-4e11-b6e9-bc3a883b2e8b)

**Environment**

Ensuring you use the relevant python executable, please paste the output of:

```
python -c "import monai; monai.config.print_debug_info()"
```
Well, the import statement crashes, so this info cannot be given.

**Additional context**
I am pretty sure it has to do with "find_module" being deprecated in python 3.12, as well as the "load_module" function in monai.utils.module.py (line 210 and following). Probably needs to be replaced with the 3.12 version of those function calls.


Python 3.12 import AttributeError: 'FileFinder' object has no attribute 'find_module'
**Describe the bug**
When installing monai (via pip) into a conda environment of python 3.12.1, I get a 
"
AttributeError: 'FileFinder' object has no attribute 'find_module'
"
as soon as i call "import monai"

**To Reproduce**
Steps to reproduce the behavior:
1. conda create --name test python=3.12
2. conda activate test
3. pip install monai
4. python
5. import monai
-> see screenshot below


**Expected behavior**
I should be able to import monai

**Screenshots**
installing monai triggered a lot of other package installations: 
![Screenshot from 2024-02-09 13-06-58](https://github.com/Project-MONAI/MONAI/assets/19862882/71118752-d811-4034-af86-1c0eb70a625a)

![Screenshot from 2024-02-09 13-03-27](https://github.com/Project-MONAI/MONAI/assets/19862882/7b505ba6-1501-4e11-b6e9-bc3a883b2e8b)

**Environment**

Ensuring you use the relevant python executable, please paste the output of:

```
python -c "import monai; monai.config.print_debug_info()"
```
Well, the import statement crashes, so this info cannot be given.

**Additional context**
I am pretty sure it has to do with "find_module" being deprecated in python 3.12, as well as the "load_module" function in monai.utils.module.py (line 210 and following). Probably needs to be replaced with the 3.12 version of those function calls.




Discussion:
I am facing the same issue. Have you resolved it? Do I need to depreciate the python library to lower version?
> I am facing the same issue. Have you resolved it? Do I need to depreciate the python library to lower version?

I just downgraded Python to 11* version and installed monai, and it worked!
I am facing the same issue. Have you resolved it? Do I need to depreciate the python library to lower version?
> I am facing the same issue. Have you resolved it? Do I need to depreciate the python library to lower version?

I just downgraded Python to 11* version and installed monai, and it worked!

Resolving patch:
diff --git a/monai/utils/module.py b/monai/utils/module.py
--- a/monai/utils/module.py
+++ b/monai/utils/module.py
@@ -209,7 +209,7 @@ 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)
-                importer.find_module(name).load_module(name)  # type: ignore
+                importer.find_spec(name).loader.load_module(name)  # type: ignore
                 submodules.append(mod)
             except OptionalImportError:
                 pass  # could not import the optional deps., they are ignored


Test patch: