guard_import#

langchain_core.utils.utils.guard_import(module_name: str, *, pip_name: str | None = None, package: str | None = None) Any[source]#

Dynamically import a module and raise an exception if the module is not installed.

Parameters:
  • module_name (str) – The name of the module to import.

  • pip_name (str, optional) – The name of the module to install with pip. Defaults to None.

  • package (str, optional) – The package to import the module from. Defaults to None.

Returns:

The imported module.

Return type:

Any

Raises:

ImportError – If the module is not installed.