""" Legacy Python.NET loader for backwards compatibility """ def _get_netfx_path(): import os, sys if sys.maxsize > 2 ** 32: arch = "amd64" else: arch = "x86" return os.path.join(os.path.dirname(__file__), "pythonnet", "netfx", arch, "clr.pyd") def _get_mono_path(): import os, glob pattern = os.path.join(os.path.dirname(__file__), "pythonnet", "mono", "clr.*so") paths = glob.glob(pattern) if len(paths) == 0: raise FileNotFoundError( "Unable to find any file '*.so' with pattern %r." % pattern) return paths[0] def _load_clr(): import sys from importlib import util if sys.platform == "win32": path = _get_netfx_path() else: # only mono works on Windows path = _get_mono_path() del sys.modules[__name__] spec = util.spec_from_file_location("clr", path) if spec is None: raise ImportError( "Unable to import %r as 'clr'." % path) clr = util.module_from_spec(spec) spec.loader.exec_module(clr) sys.modules[__name__] = clr _load_clr()