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 Python 3.12 compatibility - use importlib.util.find_spec("numpy") instead of imp #986

Open
nicklasb opened this issue Sep 8, 2024 · 1 comment

Comments

@nicklasb
Copy link

nicklasb commented Sep 8, 2024

Hi!

In the pip distribution (at least on windows), in flatbuffers\compat.py, it uses imp, which is removed in python 3.12, so I had to monkey patch it to use importlib instead to make the library work properly.

I couldn't find that code anywhere, so I suppose it is in some pip package source somewhere, otherwise I'd made a PR.

@ozkulah
Copy link

ozkulah commented Jan 8, 2025

Any update on this? It is only used for ;

def import_numpy():
    """
    Returns the numpy module if it exists on the system,
    otherwise returns None.
    """
    try:
        imp.find_module('numpy')
        numpy_exists = True
    except ImportError:
        numpy_exists = False

    if numpy_exists:
        # We do this outside of try/except block in case numpy exists
        # but is not installed correctly. We do not want to catch an
        # incorrect installation which would manifest as an
        # ImportError.
        import numpy as np
    else:
        np = None

    return np

and that doesn't seem as a vital thing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants