{"record":{"id":"3f7c9cd4743828ca","repo":"deepinsight/insightface","slug":"could-not-load-s","errorCode":null,"errorMessage":"Could not load %s.","messagePattern":"Could not load (.+?)\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"critical","filePath":"cpp-package/inspireface/python/inspireface/modules/core/native.py","lineNumber":630,"sourceCode":"\n        def __getattr__(self, name):\n            return getattr(self.access[\"cdecl\"], name)\n\n    def __init__(self):\n        self.other_dirs = []\n\n    def __call__(self, libname):\n        \"\"\"Given the name of a library, load it.\"\"\"\n        paths = self.getpaths(libname)\n\n        for path in paths:\n            # noinspection PyBroadException\n            try:\n                return self.Lookup(path)\n            except Exception as err:  # pylint: disable=broad-except\n                print(err)\n\n        raise ImportError(\"Could not load %s.\" % libname)\n\n    def getpaths(self, libname):\n        \"\"\"Return a list of paths where the library might be found.\"\"\"\n        if os.path.isabs(libname):\n            yield libname\n        else:\n            # search through a prioritized series of locations for the library\n\n            # we first search any specific directories identified by user\n            for dir_i in self.other_dirs:\n                for fmt in self.name_formats:\n                    # dir_i should be absolute already\n                    yield os.path.join(dir_i, fmt % libname)\n\n            # check if this code is even stored in a physical file\n            try:\n                this_file = __file__\n            except NameError:","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/deepinsight/insightface/blob/7fadd420c2351d0ffa8cac403421c1a3ed733365/cpp-package/inspireface/python/inspireface/modules/core/native.py#L612-L648","documentation":"LibraryLoader.__call__ tried every candidate path for libname (from getpaths) and either found no readable file or every ctypes load attempt failed; each underlying error is printed, then the final ImportError 'Could not load %s.' is raised. It is the top-level failure of dynamic library resolution in the bundled ctypes shim.","triggerScenarios":"Calling the loader with a library name whose file exists in none of the searched paths, or where the file exists but dlopen fails (undefined symbols, wrong architecture, missing runtime deps like libc++/OpenCV shared libs).","commonSituations":"System missing the C++ runtime the .so was linked against; mixing a library built for a different Python/arch; LD_LIBRARY_PATH not including bundled dependencies; container without libgomp/libstdc++ installed.","solutions":["Read the printed preceding errors — they name the real cause (missing file vs dlopen symbol/dependency failure)","If dlopen deps are missing, install system runtimes: apt-get install -y libstdc++6 libgomp1 (or equivalent)","Confirm the library file exists at the expected path (see get_lib_path logic) and matches your arch","Reinstall the package from a wheel built for your platform so symbols/deps line up"],"exampleFix":"# before: ImportError: Could not load inspireface.\n# stderr shows: libstdc++.so.6: cannot open shared object file\n# after\napt-get update && apt-get install -y libstdc++6 libgomp1\npython -c \"import inspireface\"","handlingStrategy":"fallback","validationCode":"import pathlib\nlib = pathlib.Path(inspireface.__file__).parent\nassert any(lib.rglob('*.so*')) or any(lib.rglob('*.dll')), 'bundled libs absent'","typeGuard":null,"tryCatchPattern":"try:\n    import inspireface\nexcept ImportError as e:\n    if 'Could not load' in str(e):\n        # inspect printed dlopen errors; install missing system runtimes\n        raise","preventionTips":["Pre-install libstdc++6/libgomp in slim images","Capture stderr during import in CI to see the printed root-cause errors"],"tags":["native-library","dlopen","import-error","dependencies"],"backgroundTag":"shared-library-load-failed","analyzedSha":"7fadd420c2351d0ffa8cac403421c1a3ed733365","analyzedAt":"2026-08-28T15:44:01.850Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}