code: def installed_packages():
      freeze = pip(["freeze", "--all"]).decode("utf-8").splitlines()
      packages = {line.split("==")[0]: line for line in freeze}
      packages_set = frozenset(packages)
  
      # For each of the following families, expect exactly one package to be
      # installed.
      expect_unique = [
          frozenset(
              [
                  "tensorboard",
                  "tb-nightly",
                  "tensorflow-tensorboard",
              ]
          ),
          frozenset(
              [
                  "tensorflow",
                  "tensorflow-gpu",
                  "tf-nightly",
                  "tf-nightly-2.0-preview",
                  "tf-nightly-gpu",
                  "tf-nightly-gpu-2.0-preview",
              ]
          ),
          frozenset(
              [
                  "tensorflow-estimator",
                  "tensorflow-estimator-2.0-preview",
                  "tf-estimator-nightly",
              ]
          ),
      ]
      salient_extras = frozenset(["tensorboard-data-server"])
  
      found_conflict = False
      for family in expect_unique:
          actual = family & packages_set
          for package in actual:
              logging.info("installed: %s", packages[package])
          if len(actual) == 0:
              logging.warning(
                  "no installation among: %s", sorted(family)
              )
          elif len(actual) > 1:
              logging.warning(
                  "conflicting installations: %s", sorted(actual)
              )
              found_conflict = True
      for package in sorted(salient_extras & packages_set):
          logging.info("installed: %s", packages[package])
  
      if found_conflict:
          preamble = reflow(
              """
              Conflicting package installations found. Depending on the order
              of installations and uninstallations, behavior may be undefined.
              Please uninstall ALL versions of TensorFlow and TensorBoard,
              then reinstall ONLY the desired version of TensorFlow, which
              will transitively pull in the proper version of TensorBoard. (If
              you use TensorBoard without TensorFlow, just reinstall the
              appropriate version of TensorBoard directly.)
              """
          )
          packages_to_uninstall = sorted(
              frozenset().union(*expect_unique) & packages_set
          )
          commands = [
              "pip uninstall %s" % " ".join(packages_to_uninstall),
              "pip install tensorflow  # or `tensorflow-gpu`, or `tf-nightly`, ...",
          ]
          message = "%s\n\nNamely:\n\n%s" % (
              preamble,
              "\n".join("\t%s" % c for c in commands),
          )
          yield Suggestion("Fix conflicting installations", message)
  
imports: import dataclasses
  import errno
  import functools
  import hashlib
  import inspect
  import logging
  import os
  import pipes
  import shlex
  import socket
  import subprocess
  import sys
  import tempfile
  import textwrap
  import traceback
label_desc: Use image node_id 9 for calling a global function with example usage: installed_packages() without return types