声明可导入的延迟模块

(函数来自 pyomo.common.dependencies)

pyomo.common.dependencies.declare_deferred_modules_as_importable(globals_dict)[source]

已弃用。

使DeferredImportModules中的所有内容在globals_dict中可导入

此函数将遍历指定的 globals_dict 字典,并添加任何找到的 DeferredImportModule 实例(以及它们的任何延迟子模块)到 sys.modules,以便可以通过 globals_dict 命名空间导入这些模块。

例如,pyomo/common/dependencies.py 声明:

>>> scipy, scipy_available = attempt_import(
...     'scipy', callback=_finalize_scipy,
...     deferred_submodules=['stats', 'sparse', 'spatial', 'integrate'])
>>> declare_deferred_modules_as_importable(globals())
WARNING: DEPRECATED: ...

这使得用户能够使用:

>>> import pyomo.common.dependencies.scipy.sparse as spa

如果延迟导入尚未触发,则返回DeferredImportModule并将其命名为spa。然而,如果导入已经触发,则spa将是scipy.sparse模块,或者是ModuleUnavailable的实例。

自版本6.7.2起已弃用:declare_deferred_modules_as_importable() 已被弃用。请使用 declare_modules_as_importable 上下文管理器。