code: def _check_environment_and_redirect():
      """Checks that the current ``sys.executable`` is the same as the executable resolved from the current environment.
  
      If not, this utility tries to redirect the ``lightning`` call to the environment executable (prompting the user to
      install lightning for them there if needed).
  
      """
      process = subprocess.run(
          ["python", "-c", "import sys; print(sys.executable)"],
          capture_output=True,
          env=os.environ,
          check=True,
      )
  
      env_executable = os.path.realpath(process.stdout.decode().strip())
      sys_executable = os.path.realpath(sys.executable)
  
      # on windows, the extension might be different, where one uses `.EXE` and the other `.exe`
      if env_executable.lower() != sys_executable.lower():
          logger.info(
              "Lightning is running from outside your current environment. Switching to your current environment."
          )
  
          process = subprocess.run(
              [env_executable, "-m", "lightning", "--version"],
              capture_output=True,
              text=True,
          )
  
          if "No module named lightning" in process.stderr:
              prompt = f"The {__package_name__} package is not installed. Would you like to install it? [Y/n (exit)]"
  
              if click.confirm(
                  prompt, default=True, show_default=False
              ):
                  command = f"pip install {__package_name__}"
  
                  logger.info(f"⚡ RUN: {command}")
  
                  subprocess.run(
                      [env_executable, "-m"] + command.split(" "),
                      check=True,
                  )
              else:
                  sys.exit()
  
          _redirect_command(env_executable)
      return
  
imports: import contextlib
  import functools
  import json
  import os
  import re
  import subprocess
  import sys
  from typing import Dict, Optional
  import arrow
  import click
  import packaging
  import requests
  import rich
  from lightning_cloud.openapi import Externalv1LightningappInstance
  from lightning.app import __package_name__, __version__
  from lightning.app.core.constants import APP_SERVER_PORT
  from lightning.app.utilities.app_helpers import Logger
  from lightning.app.utilities.cloud import _get_project
  from lightning.app.utilities.network import LightningClient
label_desc: Use image node_id 10 for calling a global function with example usage: _check_environment_and_redirect() without return types