Support Questions

Find answers, ask questions, and share your expertise

Correct python version for python extension

avatar
Super Guru

Hi,

Anyone knows if there is compatibility issue for using python exntension with the latest python version 3.12. To me the 3.12 doesnt seem to work well with the python extension and I keep getting the following error :

AttributeError: 'FileFinder' object has no attribute 'find_module'
2024-05-16 22:12:52,884 ERROR python.ExtensionManager Failed to load Python extensions from module file <Unknown Module File>. This module will be ignored.
Traceback (most recent call last):
File "F:\NIFI-PORD-ENV-2.0.0-M2\python\framework\ExtensionManager.py", line 186, in __discover_extensions_from_paths
module = finder.find_module(name)

The error seems to go away when using 3.11.*

 

5 REPLIES 5

avatar

I read somewhere that for now python version from 3.9 to 3.11 are supported. A version below or above causes error.

avatar
Super Guru

Thanks @AsifArmanRahman . I thought I read it somewhere as well but I cant remember nor I can find anything about this in the traditional guides online including release notes. I hope the owners do a better job documenting these things since it saves people a lot of headache and time.

avatar

Ah I found it. In M1 guide it's mentioned python 3.9+, M2 guide it's mentioned 3.9 to 3.11 and 3.12 is not yet supported and finally in M3 guide 3.12 is supported as well. I'm just adding direct link of M3 guide for where it's mentioned below

NiFi Python Developer’s Guide (apache.org)

avatar
New Contributor

The error you are encountering is likely due to changes in the import system in Python 3.12. The `find_module` method was deprecated in Python 3.4 and removed in Python 3.12. The new import system uses `find_spec` instead.

To resolve this issue, you'll need to update the code to use `find_spec` instead of `find_module`. Here's how you can modify the relevant part of your code:

```python
Original code using find_module
module = finder.find_module(name)

Updated code using find_spec
module_spec = finder.find_spec(name)
if module_spec is not None:
module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)
else:
module = None
```

You will need to import `importlib.util` if it's not already imported:

```python
import importlib.util
```

This change should make your code compatible with Python 3.12. If you are using a third-party library that hasn't been updated yet, you may need to wait for the maintainers to release a compatible version or consider contributing a patch.

Additionally, you might want to check if there are updates or patches available for the specific Python extension you are using, as the maintainers might have already addressed this issue in a newer release.

avatar
Super Guru

Hi @zain99 ,

Thanks for your information. it definitely shed more light on why 3.12  is not working  and how it need to be  resolved. This however appears to have been addressed in 2.0.0M4 release. I have not tested it against 3.12 but I can see in the code its no longer using the find_module and using the find_spec instead.

 

Thanks