def check_imports(ignore_version_mismatch: bool = False):
    """Check required and optional package versions.
    Args:
        ignore_version_mismatch: If set, will not raise an error if a
            version mismatch is found in a required package. Regardless of
            this setting, mismatch in an optional package is a warning.
    Raises:
        VersionConflict: If a version mismatch is found in a required package
            and `ignore_version_mismatch` is not set.
    """

    for n, req in all_packages.items():
        is_optional = n in optional_packages

        try:
            dist = metadata.distribution(req.name)

        except metadata.PackageNotFoundError as e:
            if is_optional:
                logger.debug(MESSAGE_DEBUG_OPTIONAL_PACKAGE_NOT_FOUND, req.name)

            else:
                raise ModuleNotFoundError(
                    MESSAGE_ERROR_REQUIRED_PACKAGE_NOT_FOUND.format(req=req)
                ) from e

        if dist.version not in req.specifier:
            message = MESSAGE_FRAGMENT_VERSION_MISMATCH.format(
                req=req, dist=dist
            )

            if is_optional:
                message += MESSAGE_FRAGMENT_VERSION_MISMATCH_OPTIONAL.format(
                    req=req
                )

            else:
                message += MESSAGE_FRAGMENT_VERSION_MISMATCH_REQUIRED.format(
                    req=req
                )

            message += MESSAGE_FRAGMENT_VERSION_MISMATCH_PIP.format(req=req)

            if (not is_optional) and (not ignore_version_mismatch):
                raise VersionConflict(message)

            logger.debug(message)
Check required and optional package versions.
    Args:
        ignore_version_mismatch: If set, will not raise an error if a
            version mismatch is found in a required package. Regardless of
            this setting, mismatch in an optional package is a warning.
    Raises:
        VersionConflict: If a version mismatch is found in a required package
            and `ignore_version_mismatch` is not set.
    
src/core/trulens/core/utils/imports.py