From b7812d2990fa4a9cb0dafd464707371ee2cf257e Mon Sep 17 00:00:00 2001 From: wsyxbcl Date: Tue, 13 Aug 2024 17:40:18 +0800 Subject: [PATCH] check python version before import imp --- utool/util_inject.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/utool/util_inject.py b/utool/util_inject.py index 7452c5fd..25ded8f2 100755 --- a/utool/util_inject.py +++ b/utool/util_inject.py @@ -305,10 +305,15 @@ def rrr(verbose=True): if not __RELOAD_OK__: raise Exception('Reloading has been forced off') try: - import imp + v = sys.version_info + if v.major >= 3 and v.minor >= 4: + import importlib + importlib.reload(module) + else: + import imp + imp.reload(module) if verbose and not QUIET: builtins.print('RELOAD: ' + str(module_prefix) + ' __name__=' + module_name) - imp.reload(module) except Exception as ex: print(ex) print('%s Failed to reload' % module_prefix)