code: def which(program):
      
      def is_exe(fpath):
          found = os.path.isfile(fpath) and os.access(fpath, os.X_OK)
          if not found and sys.platform == 'win32':
              fpath = fpath + ".exe"
              found = os.path.isfile(fpath) and os.access(fpath, os.X_OK)
          return found
  
      fpath, _ = os.path.split(program)
      if fpath:
          if is_exe(program):
              logger.debug("found executable: " + str(program))
              return program
      else:
          for path in os.environ["PATH"].split(os.pathsep):
              path = os.path.expandvars(os.path.expanduser(path)).strip('"')
              exe_file = os.path.join(path, program)
              if is_exe(exe_file):
                  logger.debug("found executable in path: " + str(exe_file))
                  return exe_file
  
      return None
docs: Find a program in PATH and return path
      From: http://stackoverflow.com/q/377017/