code: def get_home_dir():
      
      try:
          # expanduser() returns a raw byte string which needs to be
          # decoded with the codec that the OS is using to represent
          # file paths.
          path = encoding.to_unicode_from_fs(osp.expanduser('~'))
      except Exception:
          path = ''
  
      if osp.isdir(path):
          return path
      else:
          # Get home from alternative locations
          for env_var in ('HOME', 'USERPROFILE', 'TMP'):
              # os.environ.get() returns a raw byte string which needs to be
              # decoded with the codec that the OS is using to represent
              # environment variables.
              path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
              if osp.isdir(path):
                  return path
              else:
                  path = ''
  
          if not path:
              raise RuntimeError('Please set the environment variable HOME to '
                                 'your user/home directory path so Spyder can '
                                 'start properly.')
docs: Return user home directory