text: from os.path \
      import \
          abspath, splitunc, curdir, sep, pardir, join
  
  def relpath(path, start=curdir):
      """Return a relative version of a path"""
  
      if not path:
          raise ValueError("no path specified")
      start_list = abspath(start).split(sep)
      path_list = abspath(path).split(sep)
      if start_list[0].lower() != path_list[0].lower():
          unc_path, rest = splitunc(path)
          unc_start, rest = splitunc(start)
          if bool(unc_path) ^ bool(unc_start):
              raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                  % (path, start))
          else:
              raise ValueError("path is on drive %s, start on drive %s"
                                                  % (path_list[0], start_list[0]))
      # Work out how much of the filepath is shared by start and path.
      for i in range(min(len(start_list), len(path_list))):
          if start_list[i].lower() != path_list[i].lower():
              break
      else:
          i += 1
  
      rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
      if not rel_list:
          return curdir
      return join(*rel_list)
  