Repository: pypa/virtualenv

Issue:
Cannot create a virtual env with python 2.7 on windows
**Issue**

When creating a virtual environment using python 2.7 it fails with the message:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python2.7'   

I have python 2.7, 3.7 and 3.8 installed. I can create environments for 3.7 and 3.8

**Environment**


Provide at least:
OS: Windows

```console
awscli                              1.18.16                                                                             boto3                               1.12.16                                                                             botocore                            1.15.16                                                                             cattrs                              1.0.0                                                                               cdk-watchful                        0.4.6                                                                               certifi                             2020.4.5.1                                                                          chardet                             3.0.4                                                                               colorama                            0.4.3                                                                               constructs                          2.0.1                                                                               distlib                             0.3.0                                                                               docutils                            0.15.2                                                                              filelock                            3.0.12                                                                              idna                                2.9                                                                                 importlib-metadata                  1.6.0                                                                               importlib-resources                 1.4.0                                                                               jmespath                            0.9.5                                                                               jsii                                1.1.1                                                                               pip                                 19.2.3                                                                              publication                         0.0.3                                                                               pyasn1                              0.4.8                                                                               python-dateutil                     2.8.1                                                                               PyYAML                              5.3.1                                                                               requests                            2.23.0                                                                              rsa                                 3.4.2                                                                               s3transfer                          0.3.3                                                                               setuptools                          41.2.0                                                                              six                                 1.14.0                                                                              typing-extensions                   3.7.4.2                                                                             urllib3                             1.25.9                                                                              virtualenv                          20.0.18                                                                             virtualenvwrapper-win               1.2.6                                                                               zipp                                3.1.0   
```

**Output of the virtual environment creation**

Make sure to run the creation with `-vvv --with-traceback`:

```console
PS C:\Users\WSEB\work> virtualenv --python=python2.7 test27 -vvv
61 setup logging to NOTSET [DEBUG report:43]
75 find interpreter for spec PythonSpec(implementation=CPython, major=2, minor=7) [INFO builtin:44]
76 proposed PythonInfo(spec=CPython3.8.2.final.0-64, exe=c:\python38\python.exe, platform=win32, version='3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]', encoding_fs_io=utf-8-utf-8) [INFO builtin:50]
78 discover PATH[0]=C:\Python38\Scripts\ [DEBUG builtin:84]
79 filesystem is not case-sensitive [DEBUG info:28]
79 discover PATH[1]=C:\Python38\ [DEBUG builtin:84]
80 discover PATH[2]=C:\Program Files\AdoptOpenJDK\jre-11.0.3.2-openj9\bin [DEBUG builtin:84]
81 discover PATH[3]=C:\WINDOWS\system32 [DEBUG builtin:84]
81 discover PATH[4]=C:\WINDOWS [DEBUG builtin:84]
82 discover PATH[5]=C:\WINDOWS\System32\Wbem [DEBUG builtin:84]
82 discover PATH[6]=C:\WINDOWS\System32\WindowsPowerShell\v1.0\ [DEBUG builtin:84]
82 discover PATH[7]=C:\WINDOWS\System32\OpenSSH\ [DEBUG builtin:84]
83 discover PATH[8]=C:\Program Files\Git\cmd [DEBUG builtin:84]
83 discover PATH[9]=C:\Program Files\nodejs\ [DEBUG builtin:84]
84 discover PATH[10]=C:\ProgramData\chocolatey\bin [DEBUG builtin:84]
84 discover PATH[11]=C:\Program Files\Amazon\AWSCLIV2\ [DEBUG builtin:84]
85 discover PATH[12]=C:\HashiCorp\Vagrant\bin [DEBUG builtin:84]
85 discover PATH[13]=C:\Users\WSEB\AppData\Local\Microsoft\WindowsApps [DEBUG builtin:84]
86 Attempting to acquire lock 1578932602960 on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\4e341a9637e8fd2ad6729b2fad2f450d3cd7f3301af1e9c20e7237b10809c2b7.lock [DEBUG filelock:270]
86 Lock 1578932602960 acquired on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\4e341a9637e8fd2ad6729b2fad2f450d3cd7f3301af1e9c20e7237b10809c2b7.lock [INFO filelock:274]
87 get PythonInfo from C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\4e341a9637e8fd2ad6729b2fad2f450d3cd7f3301af1e9c20e7237b10809c2b7.json for C:\Users\WSEB\AppData\Local\Microsoft\WindowsApps\python.exe [DEBUG cached_py_info:79]
87 Attempting to release lock 1578932602960 on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\4e341a9637e8fd2ad6729b2fad2f450d3cd7f3301af1e9c20e7237b10809c2b7.lock [DEBUG filelock:315]
88 Lock 1578932602960 released on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\4e341a9637e8fd2ad6729b2fad2f450d3cd7f3301af1e9c20e7237b10809c2b7.lock [INFO filelock:318]
89 Attempting to acquire lock 1578932602192 on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\2038186569936074e374468d4bbe2904a13496a41ed7a70129cfb883acf0ea5f.lock [DEBUG filelock:270]
89 Lock 1578932602192 acquired on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\2038186569936074e374468d4bbe2904a13496a41ed7a70129cfb883acf0ea5f.lock [INFO filelock:274]
90 get PythonInfo from C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\2038186569936074e374468d4bbe2904a13496a41ed7a70129cfb883acf0ea5f.json for C:\Users\WSEB\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe [DEBUG cached_py_info:79]
90 Attempting to release lock 1578932602192 on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\2038186569936074e374468d4bbe2904a13496a41ed7a70129cfb883acf0ea5f.lock [DEBUG filelock:315]
90 Lock 1578932602192 released on C:\Users\WSEB\AppData\Local\pypa\virtualenv\py_info\20.0.18\2038186569936074e374468d4bbe2904a13496a41ed7a70129cfb883acf0ea5f.lock [INFO filelock:318]
91 proposed PathPythonInfo(spec=CPython3.7.7.final.0-64, system=C:\Users\WSEB\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe, exe=C:\Users\WSEB\AppData\Local\Microsoft\WindowsApps\python.exe, platform=win32, version='3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 11:52:54) [MSC v.1900 64 bit (AMD64)]', encoding_fs_io=utf-8-cp1252) [INFO builtin:50]
91 discover PATH[14]=C:\Program Files\JetBrains\PyCharm 2020.1\bin [DEBUG builtin:84]
93 discover PATH[15]=C:\Users\WSEB\AppData\Local\hyper\app-3.0.2\resources\bin [DEBUG builtin:84]
96 discover PATH[16]=C:\Users\WSEB\AppData\Local\Programs\Microsoft VS Code\bin [DEBUG builtin:84]
97 discover PATH[17]=C:\Users\WSEB\AppData\Roaming\npm [DEBUG builtin:84]
98 discover PATH[18]=C:\Program Files\Oracle\VirtualBox [DEBUG builtin:84]
99 RuntimeError: failed to find interpreter for Builtin discover of python_spec='python2.7' [ERROR __main__:57]
```



Discussion:
How did you install python 2.7, seems it's not available in either the registry or on the ``PATH`` 🤔 

Resolving patch:
diff --git a/src/virtualenv/discovery/windows/__init__.py b/src/virtualenv/discovery/windows/__init__.py
--- a/src/virtualenv/discovery/windows/__init__.py
+++ b/src/virtualenv/discovery/windows/__init__.py
@@ -11,8 +11,15 @@ class Pep514PythonInfo(PythonInfo):
 
 def propose_interpreters(spec, cache_dir):
     # see if PEP-514 entries are good
-    for name, major, minor, arch, exe, _ in discover_pythons():
+
+    # start with higher python versions in an effort to use the latest version available
+    existing = list(discover_pythons())
+    existing.sort(key=lambda i: tuple(-1 if j is None else j for j in i[1:4]), reverse=True)
+
+    for name, major, minor, arch, exe, _ in existing:
         # pre-filter
+        if name in ("PythonCore", "ContinuumAnalytics"):
+            name = "CPython"
         registry_spec = PythonSpec(None, name, major, minor, None, arch, exe)
         if registry_spec.satisfies(spec):
             interpreter = Pep514PythonInfo.from_exe(exe, cache_dir, raise_on_error=False)
diff --git a/src/virtualenv/discovery/windows/pep514.py b/src/virtualenv/discovery/windows/pep514.py
--- a/src/virtualenv/discovery/windows/pep514.py
+++ b/src/virtualenv/discovery/windows/pep514.py
@@ -73,8 +73,7 @@ def process_tag(hive_name, company, company_key, tag, default_arch):
                 exe_data = load_exe(hive_name, company, company_key, tag)
                 if exe_data is not None:
                     exe, args = exe_data
-                    name = str("python") if company == "PythonCore" else company
-                    return name, major, minor, arch, exe, args
+                    return company, major, minor, arch, exe, args
 
 
 def load_exe(hive_name, company, company_key, tag):


Test patch:
diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py
--- a/tests/unit/create/test_creator.py
+++ b/tests/unit/create/test_creator.py
@@ -330,8 +330,6 @@ def cross_python(is_inside_ci, session_app_data):
 @pytest.mark.slow
 def test_cross_major(cross_python, coverage_env, tmp_path, session_app_data, current_fastest):
     cmd = [
-        "-v",
-        "-v",
         "-p",
         ensure_text(cross_python.executable),
         ensure_text(str(tmp_path)),
diff --git a/tests/unit/discovery/windows/test_windows_pep514.py b/tests/unit/discovery/windows/test_windows_pep514.py
--- a/tests/unit/discovery/windows/test_windows_pep514.py
+++ b/tests/unit/discovery/windows/test_windows_pep514.py
@@ -17,16 +17,16 @@ def test_pep514(_mock_registry):
 
     interpreters = list(discover_pythons())
     assert interpreters == [
-        ("ContinuumAnalytics", 3, 7, 32, "C:\\Users\\traveler\\Miniconda3\\python.exe", None),
-        ("ContinuumAnalytics", 3, 7, 64, "C:\\Users\\traveler\\Miniconda3-64\\python.exe", None),
-        ("python", 3, 6, 64, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
-        ("python", 3, 6, 64, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
-        ("python", 3, 5, 64, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python35\\python.exe", None),
-        ("python", 3, 6, 64, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
-        ("python", 3, 7, 32, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", None),
-        ("python", 3, 9, 64, "C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
-        ("python", 2, 7, 64, "C:\\Python27\\python.exe", None),
-        ("python", 3, 4, 64, "C:\\Python34\\python.exe", None),
+        ("ContinuumAnalytics", 3, 7, 32, "C:\\Users\\user\\Miniconda3\\python.exe", None),
+        ("ContinuumAnalytics", 3, 7, 64, "C:\\Users\\user\\Miniconda3-64\\python.exe", None),
+        ("PythonCore", 3, 6, 64, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
+        ("PythonCore", 3, 6, 64, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
+        ("PythonCore", 3, 5, 64, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python35\\python.exe", None),
+        ("PythonCore", 3, 6, 64, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
+        ("PythonCore", 3, 7, 32, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", None),
+        ("PythonCore", 3, 9, 64, "C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", None),
+        ("PythonCore", 2, 7, 64, "C:\\Python27\\python.exe", None),
+        ("PythonCore", 3, 4, 64, "C:\\Python34\\python.exe", None),
     ]
 
 
@@ -38,16 +38,16 @@ def test_pep514_run(_mock_registry, capsys, caplog):
     out, err = capsys.readouterr()
     expected = textwrap.dedent(
         r"""
-    ('ContinuumAnalytics', 3, 7, 32, 'C:\\Users\\traveler\\Miniconda3\\python.exe', None)
-    ('ContinuumAnalytics', 3, 7, 64, 'C:\\Users\\traveler\\Miniconda3-64\\python.exe', None)
-    ('python', 2, 7, 64, 'C:\\Python27\\python.exe', None)
-    ('python', 3, 4, 64, 'C:\\Python34\\python.exe', None)
-    ('python', 3, 5, 64, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python35\\python.exe', None)
-    ('python', 3, 6, 64, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
-    ('python', 3, 6, 64, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
-    ('python', 3, 6, 64, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
-    ('python', 3, 7, 32, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe', None)
-    ('python', 3, 9, 64, 'C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
+    ('ContinuumAnalytics', 3, 7, 32, 'C:\\Users\\user\\Miniconda3\\python.exe', None)
+    ('ContinuumAnalytics', 3, 7, 64, 'C:\\Users\\user\\Miniconda3-64\\python.exe', None)
+    ('PythonCore', 2, 7, 64, 'C:\\Python27\\python.exe', None)
+    ('PythonCore', 3, 4, 64, 'C:\\Python34\\python.exe', None)
+    ('PythonCore', 3, 5, 64, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python35\\python.exe', None)
+    ('PythonCore', 3, 6, 64, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
+    ('PythonCore', 3, 6, 64, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
+    ('PythonCore', 3, 6, 64, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
+    ('PythonCore', 3, 7, 32, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe', None)
+    ('PythonCore', 3, 9, 64, 'C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe', None)
     """
     ).strip()
     assert out.strip() == expected
diff --git a/tests/unit/discovery/windows/winreg-mock-values.py b/tests/unit/discovery/windows/winreg-mock-values.py
--- a/tests/unit/discovery/windows/winreg-mock-values.py
+++ b/tests/unit/discovery/windows/winreg-mock-values.py
@@ -46,22 +46,22 @@
 value_collect = {
     78703568: {"SysVersion": ("3.7", 1), "SysArchitecture": ("32bit", 1)},
     78703200: {
-        "ExecutablePath": ("C:\\Users\\traveler\\Miniconda3\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\Miniconda3\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78702368: {"SysVersion": ("3.7", 1), "SysArchitecture": ("64bit", 1)},
     78703520: {
-        "ExecutablePath": ("C:\\Users\\traveler\\Miniconda3-64\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\Miniconda3-64\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78700704: {"SysVersion": ("3.6", 1), "SysArchitecture": ("magic", 1)},
     78701824: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78704368: {"SysVersion": ("3.6", 1), "SysArchitecture": (100, 4)},
     78704048: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78703024: {"SysVersion": ("3.6", 1), "SysArchitecture": ("64bit", 1)},
@@ -74,17 +74,17 @@
         "SysArchitecture": OSError(2, "The system cannot find the file specified"),
     },
     78703792: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python35\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python35\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78703424: {"SysVersion": ("3.6", 1), "SysArchitecture": ("64bit", 1)},
     78701888: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78704512: {"SysVersion": ("3.7", 1), "SysArchitecture": ("32bit", 1)},
     78703600: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78700656: {
@@ -93,7 +93,7 @@
     },
     78702608: {"SysVersion": ("magic", 1), "SysArchitecture": ("64bit", 1)},
     78703632: {
-        "ExecutablePath": ("C:\\Users\\traveler\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
+        "ExecutablePath": ("C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python36\\python.exe", 1),
         "ExecutableArguments": OSError(2, "The system cannot find the file specified"),
     },
     78703088: {"SysVersion": (2778, 11)},
diff --git a/tests/unit/seed/test_extra_install.py b/tests/unit/seed/test_extra_install.py
--- a/tests/unit/seed/test_extra_install.py
+++ b/tests/unit/seed/test_extra_install.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import, unicode_literals
 
 import os
+import shutil
 import subprocess
 
 import pytest
@@ -36,7 +37,9 @@ def builtin_shows_marker_missing():
 )
 @pytest.mark.parametrize("creator", list(i for i in CREATOR_CLASSES.keys() if i != "builtin"))
 def test_can_build_c_extensions(creator, tmp_path, coverage_env):
-    session = cli_run(["--creator", creator, "--seed", "app-data", str(tmp_path), "-vvv"])
+    env, greet = tmp_path / "env", str(tmp_path / "greet")
+    shutil.copytree(str(Path(__file__).parent.resolve() / "greet"), greet)
+    session = cli_run(["--creator", creator, "--seed", "app-data", str(env), "-vvv"])
     coverage_env()
     cmd = [
         str(session.creator.script("pip")),
@@ -45,7 +48,7 @@ def test_can_build_c_extensions(creator, tmp_path, coverage_env):
         "--no-deps",
         "--disable-pip-version-check",
         "-vvv",
-        str(Path(__file__).parent.resolve() / "greet"),
+        greet,
     ]
     process = Popen(cmd)
     process.communicate()