deepinsight/insightface · critical · ImportError
Could not load %s.
Error message
Could not load %s.
What it means
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.
Source
Thrown at cpp-package/inspireface/python/inspireface/modules/core/native.py:630
def __getattr__(self, name):
return getattr(self.access["cdecl"], name)
def __init__(self):
self.other_dirs = []
def __call__(self, libname):
"""Given the name of a library, load it."""
paths = self.getpaths(libname)
for path in paths:
# noinspection PyBroadException
try:
return self.Lookup(path)
except Exception as err: # pylint: disable=broad-except
print(err)
raise ImportError("Could not load %s." % libname)
def getpaths(self, libname):
"""Return a list of paths where the library might be found."""
if os.path.isabs(libname):
yield libname
else:
# search through a prioritized series of locations for the library
# we first search any specific directories identified by user
for dir_i in self.other_dirs:
for fmt in self.name_formats:
# dir_i should be absolute already
yield os.path.join(dir_i, fmt % libname)
# check if this code is even stored in a physical file
try:
this_file = __file__
except NameError:View on GitHub (pinned to 7fadd420c2)
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
Example fix
# before: ImportError: Could not load inspireface. # stderr shows: libstdc++.so.6: cannot open shared object file # after apt-get update && apt-get install -y libstdc++6 libgomp1 python -c "import inspireface"
Defensive patterns
Strategy: fallback
Validate before calling
import pathlib
lib = pathlib.Path(inspireface.__file__).parent
assert any(lib.rglob('*.so*')) or any(lib.rglob('*.dll')), 'bundled libs absent' Try / catch
try:
import inspireface
except ImportError as e:
if 'Could not load' in str(e):
# inspect printed dlopen errors; install missing system runtimes
raise Prevention
- Pre-install libstdc++6/libgomp in slim images
- Capture stderr during import in CI to see the printed root-cause errors
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Unsupported platform: system={system}, machine={machine}
- Library not found at {lib_path}. System: {system}, Architect
- Unknown calling convention '{}' for function '{}'
- OpenCV is required for video face swap: {exc}
AI-assisted analysis of deepinsight/insightface@7fadd420c2 (2026-08-28).
Data as JSON: /api/errors/3f7c9cd4743828ca.
Report an issue: GitHub.