name (str) – The name of the module to import
error_message (str, optional) – The message for the exception raised by ModuleUnavailable
only_catch_importerror (bool, optional) –
DEPRECATED: use catch_exceptions
instead of only_catch_importerror
.
If True (the default), exceptions other than ImportError
raised
during module import will be reraised. If False, any exception
will result in returning a ModuleUnavailable
object.
(deprecated in version 5.7.3)
minimum_version (str, optional) – The minimum acceptable module version (retrieved from
module.__version__
)
alt_names (list, optional) –
DEPRECATED: alt_names
no longer needs to be specified and is ignored.
A list of common alternate names by which to look for this
module in the globals()
namespaces. For example, the alt_names
for NumPy would be ['np']
. (deprecated in version 6.0)
callback (Callable[[ModuleType, bool], None], optional) – A function with the signature fcn(module, available)
that
will be called after the import is first attempted.
importer (function, optional) – A function that will perform the import and return the imported
module (or raise an ImportError
). This is useful
for cases where there are several equivalent modules and you
want to import/return the first one that is available.
defer_check (bool, optional) – DEPRECATED: renamed to defer_import
(deprecated in version 6.7.2)
defer_import (bool, optional) – If True, then the attempted import is deferred until the first
use of either the module or the availability flag. The method
will return instances of DeferredImportModule
and
DeferredImportIndicator
. If False, the import will
be attempted immediately. If not set, then the import will be
deferred unless the name
is already present in
sys.modules
.
deferred_submodules (Iterable[str], optional) – If provided, an iterable of submodule names within this module
that can be accessed without triggering a deferred import of
this module. For example, this module uses
deferred_submodules=['pyplot', 'pylab']
for matplotlib
.
catch_exceptions (Iterable[Exception], optional) – If provided, this is the list of exceptions that will be caught
when importing the target module, resulting in
attempt_import
returning a ModuleUnavailable
instance. The default is to only catch ImportError
.
This is useful when a module can regularly return additional
exceptions during import.