> For the complete documentation index, see [llms.txt](https://docs.seldon.ai/alibi-explain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seldon.ai/alibi-explain/api-reference/utils/missing_optional_dependency.md).

# alibi.utils.missing\_optional\_dependency

Functionality for optional importing

This module provides a way to import optional dependencies. In the case that the user imports some functionality from alibi that is not usable due to missing optional dependencies this code is used to allow the import but replace it with an object that throws an error on use. This way we avoid errors at import time that prevent the user using functionality independent of the missing dependency.

## Constants

### `err_msg_template`

```python
err_msg_template: string.Template = <string.Template object at 0x16e56cbe0>
```

A string class for supporting $-substitutions.

### `ERROR_TYPES`

```python
ERROR_TYPES: dict = {'ray': 'ray', 'tensorflow': 'tensorflow', 'torch': 'torch', 'pytorch': 'torc...
```

## `MissingDependency`

Missing Dependency Class

Used to replace any object that requires unmet optional dependencies. Attribute access or calling the **call** method on this object will raise an error.

### Constructor

```python
MissingDependency(self, object_name: str, err: Union[ModuleNotFoundError, ImportError], missing_dependency: str = 'all')
```

| Name                 | Type                                      | Default | Description                                              |
| -------------------- | ----------------------------------------- | ------- | -------------------------------------------------------- |
| `object_name`        | `str`                                     |         | Name of object we are replacing                          |
| `err`                | `Union[ModuleNotFoundError, ImportError]` |         | Error to be raised when the class is initialized or used |
| `missing_dependency` | `str`                                     | `'all'` | Name of missing dependency required for object           |

### Properties

| Property  | Type | Description                                                            |
| --------- | ---- | ---------------------------------------------------------------------- |
| `err_msg` | \`\` | Generate error message informing user to install missing dependencies. |

## Functions

### `import_optional`

```python
import_optional(module_name: str, names: Optional[List[str]] = None) -> typing.Any
```

Import a module that depends on optional dependencies

Note: This function is used to import modules that depend on optional dependencies. Because it mirrors the python import functionality its return type has to be `Any`. Using objects imported with this function can lead to misspecification of types as `Any` when the developer intended to be more restrictive.

| Name          | Type                  | Default | Description                                                           |
| ------------- | --------------------- | ------- | --------------------------------------------------------------------- |
| `module_name` | `str`                 |         | The module to import                                                  |
| `names`       | `Optional[List[str]]` | `None`  | The names to import from the module. If None, all names are imported. |

**Returns**

* Type: `typing.Any`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.seldon.ai/alibi-explain/api-reference/utils/missing_optional_dependency.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
