code: def fix_env(env=None):
      """Fix env variables modified by PyInstaller [1] and pyenv [2].
      [1] http://pyinstaller.readthedocs.io/en/stable/runtime-information.html
      [2] https://github.com/pyenv/pyenv/issues/985
      """
      if env is None:
          env = os.environ.copy()
      else:
          env = env.copy()
  
      if is_binary():
          lp_key = "LD_LIBRARY_PATH"
          lp_orig = env.get(lp_key + "_ORIG", None)
          if lp_orig is not None:
              env[lp_key] = lp_orig
          else:
              env.pop(lp_key, None)
  
      # Unlike PyInstaller, pyenv doesn't leave backups of original env vars
      # when it modifies them. If we look into the shim, pyenv and pyenv-exec,
      # we can figure out that the PATH is modified like this:
      #
      #     PATH=$PYENV_BIN_PATH:${bin_path}:${plugin_bin}:$PATH
      #
      # where
      #
      #     PYENV_BIN_PATH - might not start with $PYENV_ROOT if we are running
      #         `system` version of the command, see pyenv-exec source code.
      #     bin_path - might not start with $PYENV_ROOT as it runs realpath on
      #         it, but always has `libexec` part in it, see pyenv source code.
      #     plugin_bin - might contain more than 1 entry, which start with
      #         $PYENV_ROOT, see pyenv source code.
      #
      # Also, we know that whenever pyenv is running, it exports these env vars:
      #
      #     PYENV_DIR
      #     PYENV_HOOK_PATH
      #     PYENV_VERSION
      #     PYENV_ROOT
      #
      # So having this, we can make a rightful assumption about what parts of the
      # PATH we need to remove in order to get the original PATH.
      path = env.get("PATH", "")
      parts = path.split(":")
      bin_path = parts[1] if len(parts) > 2 else ""
      pyenv_dir = env.get("PYENV_DIR")
      pyenv_hook_path = env.get("PYENV_HOOK_PATH")
      pyenv_version = env.get("PYENV_VERSION")
      pyenv_root = env.get("PYENV_ROOT")
  
      env_matches = all(
          [pyenv_dir, pyenv_hook_path, pyenv_version, pyenv_root]
      )
  
      bin_path_matches = os.path.basename(bin_path) == "libexec"
  
      # NOTE: we don't support pyenv-win
      if os.name != "nt" and env_matches and bin_path_matches:
          # removing PYENV_BIN_PATH and bin_path
          parts = parts[2:]
  
          if parts:
              # removing plugin_bin from the left
              plugin_bin = os.path.join(pyenv_root, "plugins")
              while parts[0].startswith(plugin_bin):
                  del parts[0]
  
          env["PATH"] = ":".join(parts)
  
      return env
  
imports: import hashlib
  import json
  import os
  import re
  import sys
  from typing import TYPE_CHECKING, Dict, Iterable, Iterator, List, Optional, Tuple
  import colorama
label_desc: Use image node_id 8 for calling a global function with example usage: fix_env(env) and returns: env