code: def get_installed_modules() -> Dict[str, Optional[LooseVersion]]:
      """
      Get installed modules and their versions from pip metadata.
      """
      global INSTALLED_MODULES
      if not INSTALLED_MODULES:
          # Get all installed modules and their versions without
          # needing to import them.
          module_versions = {}
          # top_level.txt contains information about modules
          # in the package. It is not always present, in which case
          # the assumption is that the package name is the module name.
          # https://setuptools.pypa.io/en/latest/deprecated/python_eggs.html
          for dist in distributions():
              for pkg in (
                  dist.read_text("top_level.txt") or ""
              ).split():
                  try:
                      ver = LooseVersion(dist.metadata["Version"])
                  except Exception:
                      ver = None
                  module_versions[pkg] = ver
          INSTALLED_MODULES = module_versions
      return INSTALLED_MODULES
  
file_path: pycaret/pycaret/utils/_dependencies.py
imports: import sys
  from distutils.version import LooseVersion
  from importlib import import_module
  from typing import Dict, Optional, Union
  from importlib_metadata import distributions
  from pycaret.internal.logging import get_logger, redirect_output
label_desc: Use image node_id 2 for calling a global function with example usage: get_installed_modules() and returns: INSTALLED_MODULES