声明可导入的延迟模块
(函数来自 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上下文管理器。