text: Title: Expand ~ in paths
  Body: From #2820 (@tomaarsen)
  
  Expand ~ in paths used in environment variables to the home path of the user's operating system. This is as simple as wrapping a path with path = os.path.expanduser(path). This probably ought to be done in some functions in internals.py. However, files on linux are allowed to have ~ in them. In some of those cases, you wouldn't want to expand the ~.