code: def which(cmd):
      
      try:
          # For Python 3
          from shutil import which as _which
      except ImportError:
          # For Python 2
          from backports.shutil_which import which as _which  # pylint: disable=relative-import
      full_path = _which(cmd)
      if full_path is None:
          raise OSError('Cannot find {!r} in $PATH'.format(cmd))
      log.debug('which %r => %r', cmd, full_path)
      return full_path
docs: Return full path to specified command, or raise OSError if missing.