Repository: pypa/pipenv

Issue:
Windows update breaks pipenv virtual environments creation
### Issue description

`> pipenv install` and `> pipenv --python 3` fails in a desktop folder after windows update.


### Expected result
Creation of a virtual environment and installing all dependencies declared in Pipfile.lock
### Actual result
```
> pipenv install
Traceback (most recent call last):
  File "c:\users\ale\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Ale\AppData\Local\Programs\Python\Python36\Scripts\pipenv.exe\__main__.py", line 9, in <module>
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli\command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 1695, in do_install
    pypi_mirror=pypi_mirror,
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 561, in ensure_project
    pypi_mirror=pypi_mirror,
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 484, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 397, in ensure_python
    path_to_python = find_a_system_python(python)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 360, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 81, in find_python_version
    match = self.windows_finder.find_python_version(
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 49, in windows_finder
    self._windows_finder = WindowsFinder()
  File "<attrs generated init 87ada516ba10af7bd87735a5460aaaf86a1d070f>", line 13, in __init__
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\pythonfinder\models\windows.py", line 66, in get_versions
    path = ensure_path(install_path.__getattr__(""))
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\pythonfinder\_vendor\pep514tools\_registry.py", line 75, in __getattr__
    raise AttributeError(attr)
AttributeError
```

```
> pipenv --python 3
*
* (Same as pipenv install)
 AttributeError
```
### Steps to replicate

I was working on a project after updating windows and I wanted to test my configuration so I did
`> pipenv --rm` to delete my current environment. When I tried to use `> pipenv install --dev` I got that error.
I have already tried reinstalling pipenv and python and deleting all my site-packages. 

It once let me create an environment  in `c:\\users\\ale`, but not in other directories. I also tried `> pipenv -support`, but it failed at getting the python installations with the same error as always.
I again tested removing the environment and performing a `> pipenv install` but this time it failed.

After some testing I removed the Pipfile and Pipfile.lock in `c:\\users\\ale` and ` >pipenv install` worked again but only in that directory as creating an empty folder in the desktop or other directories and executing pipenv install always fails with the same traceback.

-------------------------------------------------------------------------------

Windows 10 Home: `'1803 (OS build 17134.345)'`

Pip version: `'18.1'`

Pipenv version: `'2018.10.9'`

Pipenv location: `'c:\\users\\ale\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\pipenv'`

Python location: `'c:\\users\\ale\\appdata\\local\\programs\\python\\python36\\python.exe'`

Python installations found:

```
Traceback (most recent call last):
 *
 * (Same error as above)
 *
  File "c:\users\ale\appdata\local\programs\python\python36\lib\site-packages\pipenv\vendor\pythonfinder\_vendor\pep514tools\_registry.py", line 75, in __getattr__
    raise AttributeError(attr)
AttributeError
```


Discussion:
Can you help test if [pep514tools](https://github.com/zooba/pep514tools) works on your machine?
Yes, pep514tools works on my machine
```
>>> import pep514tools as pt
>>> list(pt.findall())
[<environment PythonCore\2.7>, <environment PythonCore\3.6>, <environment PythonCore\3.7>, <environment ContinuumAnalytics\Anaconda36-64>, <environment PythonCore\3.6>, <environment PythonCore\2.7>]
```
I'm seeing the same problem:
Win 10 1803.
Python 3.7.0
```

pipenv install -e .
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\__main__.py", line 4, in <module>
    cli()
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\cli\command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 1724, in do_install
    pypi_mirror=pypi_mirror,
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 565, in ensure_project
    pypi_mirror=pypi_mirror,
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 488, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 401, in ensure_python
    path_to_python = find_a_system_python(python)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\core.py", line 364, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 85, in find_python_version
    match = self.windows_finder.find_python_version(
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 53, in windows_finder
    self._windows_finder = WindowsFinder()
  File "<attrs generated init edcac9548e6d4740d95ac8fb7f6f80b602817da2>", line 13, in __init__
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\pythonfinder\models\windows.py", line 68, in get_versions
    py_version = PythonVersion.from_windows_launcher(version_object)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\pythonfinder\models\python.py", line 182, in from_windows_launcher
    creation_dict = cls.parse(launcher_entry.info.version)
  File "C:\Users\User\AppData\Roaming\Python\Python37\site-packages\pipenv\vendor\pythonfinder\_vendor\pep514tools\_registry.py", line 75, in __getattr__
    raise AttributeError(attr)
AttributeError: version
```
These are not the same issue. Please fill out the full issue template. 
I have a very similar issue using a fresh installed python 3.6 and also tried a fresh 3.7 on my windows 10 system:

```
pipenv install
Traceback (most recent call last):
  File "c:\program files\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python36\Scripts\pipenv.exe\__main__.py", line 9, in <module>
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\click\decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\program files\python36\lib\site-packages\pipenv\cli\command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "c:\program files\python36\lib\site-packages\pipenv\core.py", line 1724, in do_install
    pypi_mirror=pypi_mirror,
  File "c:\program files\python36\lib\site-packages\pipenv\core.py", line 565, in ensure_project
    pypi_mirror=pypi_mirror,
  File "c:\program files\python36\lib\site-packages\pipenv\core.py", line 488, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "c:\program files\python36\lib\site-packages\pipenv\core.py", line 401, in ensure_python
    path_to_python = find_a_system_python(python)
  File "c:\program files\python36\lib\site-packages\pipenv\core.py", line 364, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 85, in find_python_version
    match = self.windows_finder.find_python_version(
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\pythonfinder\pythonfinder.py", line 53, in windows_finder
    self._windows_finder = WindowsFinder()
  File "<attrs generated init b2e341b0215e3c35e816b36d635b3aaaa24df2a7>", line 13, in __init__
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\pythonfinder\models\windows.py", line 66, in get_versions
    path = ensure_path(install_path.__getattr__(""))
  File "c:\program files\python36\lib\site-packages\pipenv\vendor\pythonfinder\_vendor\pep514tools\_registry.py", line 75, in __getattr__
    raise AttributeError(attr)
AttributeError
```

I have no clue how to fix that.



Resolving patch:
diff --git a/pipenv/vendor/pythonfinder/__init__.py b/pipenv/vendor/pythonfinder/__init__.py
--- a/pipenv/vendor/pythonfinder/__init__.py
+++ b/pipenv/vendor/pythonfinder/__init__.py
@@ -1,6 +1,6 @@
 from __future__ import print_function, absolute_import
 
-__version__ = '1.1.6'
+__version__ = '1.1.7.dev0'
 
 # Add NullHandler to "pythonfinder" logger, because Python2's default root
 # logger has no handler and warnings like this would be reported:
diff --git a/pipenv/vendor/pythonfinder/cli.py b/pipenv/vendor/pythonfinder/cli.py
--- a/pipenv/vendor/pythonfinder/cli.py
+++ b/pipenv/vendor/pythonfinder/cli.py
@@ -56,7 +56,20 @@ def cli(ctx, find=False, which=False, findall=False, version=False, ignore_unsup
         click.secho("Searching for python: {0!s}".format(find.strip()), fg="yellow")
         found = finder.find_python_version(find.strip())
         if found:
+            py = found.py_version
+            comes_from = getattr(py, "comes_from", None)
+            if comes_from is not None:
+                comes_from_path = getattr(comes_from, "path", found.path)
+            else:
+                comes_from_path = found.path
+            arch = getattr(py, "architecture", None)
             click.secho("Found python at the following locations:", fg="green")
+            click.secho(
+                "{py.name!s}: {py.version!s} ({py.architecture!s}) @ {comes_from!s}".format(
+                    py=py, comes_from=comes_from_path
+                ),
+                fg="yellow",
+            )
             sys.exit(0)
         else:
             click.secho("Failed to find matching executable...", fg="yellow")
diff --git a/pipenv/vendor/pythonfinder/models/windows.py b/pipenv/vendor/pythonfinder/models/windows.py
--- a/pipenv/vendor/pythonfinder/models/windows.py
+++ b/pipenv/vendor/pythonfinder/models/windows.py
@@ -84,7 +84,10 @@ def get_versions(self):
             install_path = getattr(version_object.info, "install_path", None)
             if install_path is None:
                 continue
-            path = ensure_path(install_path.__getattr__(""))
+            try:
+                path = ensure_path(install_path.__getattr__(""))
+            except AttributeError:
+                continue
             try:
                 py_version = PythonVersion.from_windows_launcher(version_object)
             except InvalidPythonVersion:


Test patch: