from dascore.utils.misc import optional_import
from dascore.exceptions import MissingOptionalDependencyError
# import a module (this is the same as import dascore as dc)
= optional_import('dascore')
dc try:
'boblib5') # doesn't exist so this raises
optional_import(except MissingOptionalDependencyError:
pass
optional_import
optional_import(
package_name: str ,
)-> ‘ModuleType’
Import a module and return the module object if installed, else raise error.
Parameters
Parameter | Description |
---|---|
package_name |
The name of the package which may or may not be installed. Can also be sub-packages/modules (eg dascore.core). |
Raises
MissingOptionalDependency if the package is not installed.