Repository: python/mypy

Issue:
typeshed not being found on windows user install
```powershell
PS D:\testing> git clone https://github.com/python/mypy.git
# no errors

PS D:\testing> cd .\mypy\

PS D:\testing\mypy> git submodule update --init typeshed
# worked, checked out '55dbb967ad006d5835590c53ab023774dc5a1341'

PS D:\testing\mypy> pip install --user --upgrade .
Processing D:\testing\mypy
Requirement already up-to-date: typed-ast<1.2.0,>=1.1.0 in c:\users\[redacted!]\appdata\roaming\python\python36\site-packages (from mypy===0.530-dev-2bd11f60f0a0332b4c9537983a6ac7da4416e9ca)
Installing collected packages: mypy
  Running setup.py install for mypy ... done
Successfully installed mypy-0.530-dev-2bd11f60f0a0332b4c9537983a6ac7da4416e9ca

PS D:\testing\mypy> mypy setup.py  # to test
Could not resolve typeshed subdirectories. If you are using MyPyfrom source, you need to run "git submodule --init update".Otherwise your MyPy install is broken.
```

The data directory (after searching for `typeshed`) appears to be `%AppData%\Python\lib\mypy`

full path: `C:\Users\[redacted!]\AppData\Roaming\Python\lib\mypy`

```powershell
PS D:\testing\mypy> ls $Env:AppData\Python\lib\mypy

typeshed
xml
```

using this directory leads to more expected results

```powershell
PS D:\testing\mypy> mypy --custom-typeshed-dir $Env:AppData\Python\lib\mypy\typeshed setup.py
setup.py:15: error: No library stub file for module 'setuptools'
setup.py:15: note: (Stub files are from https://github.com/python/typeshed)
setup.py:16: error: No library stub file for module 'setuptools.command.build_py'
setup.py:74: error: Need type annotation for variable
```


Discussion:
It would seem that mypy's search for typeshed needs to be augmented with a case for this type of configuration. Mypy itself is at `$HOME\appdata\roaming\python\python36\site-packages\mypy` and typeshed is at `$HOME\AppData\Python\lib\mypy\typeshed`. Could you take a debugger and step through the `default_data_dir()` function (or insert some print statements) to find out where it goes wrong? I'm guessing the reason might be that it's looking for a component of the path named `lib`, but in your case there isn't one.

How did your Python install get in that location? I don't think that's where the Windows installers downloaded from python.org put it (but I might be wrong).
I can debug this.

>How did your Python install get in that location? I don't think that's where the Windows installers downloaded from python.org put it (but I might be wrong).

For me the default 3.x install directory for the newer installers (3.5+) point to `%USERPROFILE%\AppData\Local\Programs\Python\PythonXY` instead of `C:\PythonXY`.

Resolving patch:
diff --git a/mypy/build.py b/mypy/build.py
--- a/mypy/build.py
+++ b/mypy/build.py
@@ -223,10 +223,13 @@ def default_data_dir(bin_dir: Optional[str]) -> str:
             # or .../blah/lib64/python3.N/dist-packages/mypy/build.py (Gentoo)
             # or .../blah/lib/site-packages/mypy/build.py (Windows)
             # blah may be a virtualenv or /usr/local.  We want .../blah/lib/mypy.
+            # On Windows, if the install is .../python/PythonXY/site-packages, we want
+            # .../python/lib/mypy
             lib = parent
             for i in range(2):
                 lib = os.path.dirname(lib)
-                if os.path.basename(lib) in ('lib', 'lib32', 'lib64'):
+                if os.path.basename(lib) in ('lib', 'lib32', 'lib64') \
+                        or os.path.basename(lib).startswith('python'):
                     return os.path.join(os.path.dirname(lib), 'lib/mypy')
         subdir = os.path.join(parent, 'lib', 'mypy')
         if os.path.isdir(subdir):
@@ -299,9 +302,10 @@ def default_lib_path(data_dir: str,
     if sys.platform != 'win32':
         path.append('/usr/local/lib/mypy')
     if not path:
-        print("Could not resolve typeshed subdirectories. If you are using MyPy"
-              "from source, you need to run \"git submodule --init update\"."
-              "Otherwise your MyPy install is broken.", file=sys.stderr)
+        print("Could not resolve typeshed subdirectories. If you are using mypy\n"
+              "from source, you need to run \"git submodule --init update\".\n"
+              "Otherwise your mypy install is broken.\nPython executable is located at "
+              "{0}.\nMypy located at {1}".format(sys.executable, data_dir), file=sys.stderr)
         sys.exit(1)
     return path
 


Test patch: