We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
C:\python3\python.exe does not exist while running pre-commit on Windows
Hi,

I'm trying to run the pre-commit commands of the [ESSS/barril](https://github.com/ESSS/barril) repository on my Windows machine, but I'm getting this error:

```
 λ tox -e linting
linting installed: aspy.yaml==1.1.1,cfgv==1.4.0,identify==1.1.8,importlib-metadata==0.8,importlib-resources==1.0.2,nodeenv==1.3.3,pre-commit==1.14.0,PyYAML==3.13,six==1.12.0,toml==0.10.0,virtualenv==16.2.0,zipp==0.3.3
linting run-test-pre: PYTHONHASHSEED='554'
linting runtests: commands[0] | pre-commit run --all-files --show-diff-on-failure
[INFO] Installing environment for https://github.com/ambv/black.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('w:\\projects\\barril\\.tox\\linting\\scripts\\python.exe', '-mvirtualenv', 'C:\\Users\\darci\\.cache\\pre-commit\\repoufam_s8_\\py_env-python3', '-p', 'C:\\python3\\python.exe')
Return code: 3
Expected return code: 0
Output:
    The path C:\python3\python.exe (from --python=C:\python3\python.exe) does not exist

Errors: (none)

Check the log at C:\Users\darci/.cache\pre-commit\pre-commit.log
```

The `C:\python3` path does not exist on my machine, I'm using `conda` and `virtualenv` to create a Python 3.6 virtual environment, from which I execute `tox -e linting`.

Here's the contents of the `pre-commit-config.yaml`:

```yaml
repos:
-   repo: https://github.com/ambv/black
    rev: 18.6b4
    hooks:
    -   id: black
        args: [--safe, --quiet]
        language_version: python3
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v1.3.0
    hooks:
    -   id: trailing-whitespace
    -   id: end-of-file-fixer
    -   id: check-yaml
    -   id: debug-statements
    -   id: flake8
-   repo: local
    hooks:
    -   id: rst
        name: rst
        entry: rst-lint --encoding utf-8
        files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst)$
        language: python
        additional_dependencies: [pygments, restructuredtext_lint]
```

Any hints of what the problem might be?

cc @nicoddemus 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/languages/python.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 import contextlib
4 import os
5 import sys
6 
7 import pre_commit.constants as C
8 from pre_commit.envcontext import envcontext
9 from pre_commit.envcontext import UNSET
10 from pre_commit.envcontext import Var
11 from pre_commit.languages import helpers
12 from pre_commit.parse_shebang import find_executable
13 from pre_commit.util import CalledProcessError
14 from pre_commit.util import clean_path_on_failure
15 from pre_commit.util import cmd_output
16 
17 
18 ENVIRONMENT_DIR = 'py_env'
19 
20 
21 def bin_dir(venv):
22     """On windows there's a different directory for the virtualenv"""
23     bin_part = 'Scripts' if os.name == 'nt' else 'bin'
24     return os.path.join(venv, bin_part)
25 
26 
27 def get_env_patch(venv):
28     return (
29         ('PYTHONHOME', UNSET),
30         ('VIRTUAL_ENV', venv),
31         ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),
32     )
33 
34 
35 def _find_by_py_launcher(version):  # pragma: no cover (windows only)
36     if version.startswith('python'):
37         try:
38             return cmd_output(
39                 'py', '-{}'.format(version[len('python'):]),
40                 '-c', 'import sys; print(sys.executable)',
41             )[1].strip()
42         except CalledProcessError:
43             pass
44 
45 
46 def _get_default_version():  # pragma: no cover (platform dependent)
47     def _norm(path):
48         _, exe = os.path.split(path.lower())
49         exe, _, _ = exe.partition('.exe')
50         if find_executable(exe) and exe not in {'python', 'pythonw'}:
51             return exe
52 
53     # First attempt from `sys.executable` (or the realpath)
54     # On linux, I see these common sys.executables:
55     #
56     # system `python`: /usr/bin/python -> python2.7
57     # system `python2`: /usr/bin/python2 -> python2.7
58     # virtualenv v: v/bin/python (will not return from this loop)
59     # virtualenv v -ppython2: v/bin/python -> python2
60     # virtualenv v -ppython2.7: v/bin/python -> python2.7
61     # virtualenv v -ppypy: v/bin/python -> v/bin/pypy
62     for path in {sys.executable, os.path.realpath(sys.executable)}:
63         exe = _norm(path)
64         if exe:
65             return exe
66 
67     # Next try the `pythonX.X` executable
68     exe = 'python{}.{}'.format(*sys.version_info)
69     if find_executable(exe):
70         return exe
71 
72     if _find_by_py_launcher(exe):
73         return exe
74 
75     # Give a best-effort try for windows
76     if os.path.exists(r'C:\{}\python.exe'.format(exe.replace('.', ''))):
77         return exe
78 
79     # We tried!
80     return C.DEFAULT
81 
82 
83 def get_default_version():
84     # TODO: when dropping python2, use `functools.lru_cache(maxsize=1)`
85     try:
86         return get_default_version.cached_version
87     except AttributeError:
88         get_default_version.cached_version = _get_default_version()
89         return get_default_version()
90 
91 
92 def norm_version(version):
93     if os.name == 'nt':  # pragma: no cover (windows)
94         # Try looking up by name
95         version_exec = find_executable(version)
96         if version_exec and version_exec != version:
97             return version_exec
98 
99         version_exec = _find_by_py_launcher(version)
100         if version_exec:
101             return version_exec
102 
103         # If it is in the form pythonx.x search in the default
104         # place on windows
105         if version.startswith('python'):
106             return r'C:\{}\python.exe'.format(version.replace('.', ''))
107 
108     # Otherwise assume it is a path
109     return os.path.expanduser(version)
110 
111 
112 def py_interface(_dir, _make_venv):
113     @contextlib.contextmanager
114     def in_env(prefix, language_version):
115         envdir = prefix.path(helpers.environment_dir(_dir, language_version))
116         with envcontext(get_env_patch(envdir)):
117             yield
118 
119     def healthy(prefix, language_version):
120         with in_env(prefix, language_version):
121             retcode, _, _ = cmd_output(
122                 'python', '-c',
123                 'import ctypes, datetime, io, os, ssl, weakref',
124                 retcode=None,
125             )
126         return retcode == 0
127 
128     def run_hook(hook, file_args):
129         with in_env(hook.prefix, hook.language_version):
130             return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)
131 
132     def install_environment(prefix, version, additional_dependencies):
133         additional_dependencies = tuple(additional_dependencies)
134         directory = helpers.environment_dir(_dir, version)
135 
136         env_dir = prefix.path(directory)
137         with clean_path_on_failure(env_dir):
138             if version != C.DEFAULT:
139                 python = norm_version(version)
140             else:
141                 python = os.path.realpath(sys.executable)
142             _make_venv(env_dir, python)
143             with in_env(prefix, version):
144                 helpers.run_setup_cmd(
145                     prefix, ('pip', 'install', '.') + additional_dependencies,
146                 )
147 
148     return in_env, healthy, run_hook, install_environment
149 
150 
151 def make_venv(envdir, python):
152     env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1')
153     cmd = (sys.executable, '-mvirtualenv', envdir, '-p', python)
154     cmd_output(*cmd, env=env, cwd='/')
155 
156 
157 _interface = py_interface(ENVIRONMENT_DIR, make_venv)
158 in_env, healthy, run_hook, install_environment = _interface
159
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py
--- a/pre_commit/languages/python.py
+++ b/pre_commit/languages/python.py
@@ -89,8 +89,26 @@
         return get_default_version()
 
 
+def _sys_executable_matches(version):
+    if version == 'python':
+        return True
+    elif not version.startswith('python'):
+        return False
+
+    try:
+        info = tuple(int(p) for p in version[len('python'):].split('.'))
+    except ValueError:
+        return False
+
+    return sys.version_info[:len(info)] == info
+
+
 def norm_version(version):
     if os.name == 'nt':  # pragma: no cover (windows)
+        # first see if our current executable is appropriate
+        if _sys_executable_matches(version):
+            return sys.executable
+
         # Try looking up by name
         version_exec = find_executable(version)
         if version_exec and version_exec != version:

{"golden_diff": "diff --git a/pre_commit/languages/python.py b/pre_commit/languages/python.py\n--- a/pre_commit/languages/python.py\n+++ b/pre_commit/languages/python.py\n@@ -89,8 +89,26 @@\n         return get_default_version()\n \n \n+def _sys_executable_matches(version):\n+    if version == 'python':\n+        return True\n+    elif not version.startswith('python'):\n+        return False\n+\n+    try:\n+        info = tuple(int(p) for p in version[len('python'):].split('.'))\n+    except ValueError:\n+        return False\n+\n+    return sys.version_info[:len(info)] == info\n+\n+\n def norm_version(version):\n     if os.name == 'nt':  # pragma: no cover (windows)\n+        # first see if our current executable is appropriate\n+        if _sys_executable_matches(version):\n+            return sys.executable\n+\n         # Try looking up by name\n         version_exec = find_executable(version)\n         if version_exec and version_exec != version:\n", "issue": "C:\\python3\\python.exe does not exist while running pre-commit on Windows\nHi,\r\n\r\nI'm trying to run the pre-commit commands of the [ESSS/barril](https://github.com/ESSS/barril) repository on my Windows machine, but I'm getting this error:\r\n\r\n```\r\n \u03bb tox -e linting\r\nlinting installed: aspy.yaml==1.1.1,cfgv==1.4.0,identify==1.1.8,importlib-metadata==0.8,importlib-resources==1.0.2,nodeenv==1.3.3,pre-commit==1.14.0,PyYAML==3.13,six==1.12.0,toml==0.10.0,virtualenv==16.2.0,zipp==0.3.3\r\nlinting run-test-pre: PYTHONHASHSEED='554'\r\nlinting runtests: commands[0] | pre-commit run --all-files --show-diff-on-failure\r\n[INFO] Installing environment for https://github.com/ambv/black.\r\n[INFO] Once installed this environment will be reused.\r\n[INFO] This may take a few minutes...\r\nAn unexpected error has occurred: CalledProcessError: Command: ('w:\\\\projects\\\\barril\\\\.tox\\\\linting\\\\scripts\\\\python.exe', '-mvirtualenv', 'C:\\\\Users\\\\darci\\\\.cache\\\\pre-commit\\\\repoufam_s8_\\\\py_env-python3', '-p', 'C:\\\\python3\\\\python.exe')\r\nReturn code: 3\r\nExpected return code: 0\r\nOutput:\r\n    The path C:\\python3\\python.exe (from --python=C:\\python3\\python.exe) does not exist\r\n\r\nErrors: (none)\r\n\r\nCheck the log at C:\\Users\\darci/.cache\\pre-commit\\pre-commit.log\r\n```\r\n\r\nThe `C:\\python3` path does not exist on my machine, I'm using `conda` and `virtualenv` to create a Python 3.6 virtual environment, from which I execute `tox -e linting`.\r\n\r\nHere's the contents of the `pre-commit-config.yaml`:\r\n\r\n```yaml\r\nrepos:\r\n-   repo: https://github.com/ambv/black\r\n    rev: 18.6b4\r\n    hooks:\r\n    -   id: black\r\n        args: [--safe, --quiet]\r\n        language_version: python3\r\n-   repo: https://github.com/pre-commit/pre-commit-hooks\r\n    rev: v1.3.0\r\n    hooks:\r\n    -   id: trailing-whitespace\r\n    -   id: end-of-file-fixer\r\n    -   id: check-yaml\r\n    -   id: debug-statements\r\n    -   id: flake8\r\n-   repo: local\r\n    hooks:\r\n    -   id: rst\r\n        name: rst\r\n        entry: rst-lint --encoding utf-8\r\n        files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst)$\r\n        language: python\r\n        additional_dependencies: [pygments, restructuredtext_lint]\r\n```\r\n\r\nAny hints of what the problem might be?\r\n\r\ncc @nicoddemus \n", "before_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os\nimport sys\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import UNSET\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.parse_shebang import find_executable\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\n\n\nENVIRONMENT_DIR = 'py_env'\n\n\ndef bin_dir(venv):\n    \"\"\"On windows there's a different directory for the virtualenv\"\"\"\n    bin_part = 'Scripts' if os.name == 'nt' else 'bin'\n    return os.path.join(venv, bin_part)\n\n\ndef get_env_patch(venv):\n    return (\n        ('PYTHONHOME', UNSET),\n        ('VIRTUAL_ENV', venv),\n        ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),\n    )\n\n\ndef _find_by_py_launcher(version):  # pragma: no cover (windows only)\n    if version.startswith('python'):\n        try:\n            return cmd_output(\n                'py', '-{}'.format(version[len('python'):]),\n                '-c', 'import sys; print(sys.executable)',\n            )[1].strip()\n        except CalledProcessError:\n            pass\n\n\ndef _get_default_version():  # pragma: no cover (platform dependent)\n    def _norm(path):\n        _, exe = os.path.split(path.lower())\n        exe, _, _ = exe.partition('.exe')\n        if find_executable(exe) and exe not in {'python', 'pythonw'}:\n            return exe\n\n    # First attempt from `sys.executable` (or the realpath)\n    # On linux, I see these common sys.executables:\n    #\n    # system `python`: /usr/bin/python -> python2.7\n    # system `python2`: /usr/bin/python2 -> python2.7\n    # virtualenv v: v/bin/python (will not return from this loop)\n    # virtualenv v -ppython2: v/bin/python -> python2\n    # virtualenv v -ppython2.7: v/bin/python -> python2.7\n    # virtualenv v -ppypy: v/bin/python -> v/bin/pypy\n    for path in {sys.executable, os.path.realpath(sys.executable)}:\n        exe = _norm(path)\n        if exe:\n            return exe\n\n    # Next try the `pythonX.X` executable\n    exe = 'python{}.{}'.format(*sys.version_info)\n    if find_executable(exe):\n        return exe\n\n    if _find_by_py_launcher(exe):\n        return exe\n\n    # Give a best-effort try for windows\n    if os.path.exists(r'C:\\{}\\python.exe'.format(exe.replace('.', ''))):\n        return exe\n\n    # We tried!\n    return C.DEFAULT\n\n\ndef get_default_version():\n    # TODO: when dropping python2, use `functools.lru_cache(maxsize=1)`\n    try:\n        return get_default_version.cached_version\n    except AttributeError:\n        get_default_version.cached_version = _get_default_version()\n        return get_default_version()\n\n\ndef norm_version(version):\n    if os.name == 'nt':  # pragma: no cover (windows)\n        # Try looking up by name\n        version_exec = find_executable(version)\n        if version_exec and version_exec != version:\n            return version_exec\n\n        version_exec = _find_by_py_launcher(version)\n        if version_exec:\n            return version_exec\n\n        # If it is in the form pythonx.x search in the default\n        # place on windows\n        if version.startswith('python'):\n            return r'C:\\{}\\python.exe'.format(version.replace('.', ''))\n\n    # Otherwise assume it is a path\n    return os.path.expanduser(version)\n\n\ndef py_interface(_dir, _make_venv):\n    @contextlib.contextmanager\n    def in_env(prefix, language_version):\n        envdir = prefix.path(helpers.environment_dir(_dir, language_version))\n        with envcontext(get_env_patch(envdir)):\n            yield\n\n    def healthy(prefix, language_version):\n        with in_env(prefix, language_version):\n            retcode, _, _ = cmd_output(\n                'python', '-c',\n                'import ctypes, datetime, io, os, ssl, weakref',\n                retcode=None,\n            )\n        return retcode == 0\n\n    def run_hook(hook, file_args):\n        with in_env(hook.prefix, hook.language_version):\n            return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)\n\n    def install_environment(prefix, version, additional_dependencies):\n        additional_dependencies = tuple(additional_dependencies)\n        directory = helpers.environment_dir(_dir, version)\n\n        env_dir = prefix.path(directory)\n        with clean_path_on_failure(env_dir):\n            if version != C.DEFAULT:\n                python = norm_version(version)\n            else:\n                python = os.path.realpath(sys.executable)\n            _make_venv(env_dir, python)\n            with in_env(prefix, version):\n                helpers.run_setup_cmd(\n                    prefix, ('pip', 'install', '.') + additional_dependencies,\n                )\n\n    return in_env, healthy, run_hook, install_environment\n\n\ndef make_venv(envdir, python):\n    env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1')\n    cmd = (sys.executable, '-mvirtualenv', envdir, '-p', python)\n    cmd_output(*cmd, env=env, cwd='/')\n\n\n_interface = py_interface(ENVIRONMENT_DIR, make_venv)\nin_env, healthy, run_hook, install_environment = _interface\n", "path": "pre_commit/languages/python.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nimport contextlib\nimport os\nimport sys\n\nimport pre_commit.constants as C\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import UNSET\nfrom pre_commit.envcontext import Var\nfrom pre_commit.languages import helpers\nfrom pre_commit.parse_shebang import find_executable\nfrom pre_commit.util import CalledProcessError\nfrom pre_commit.util import clean_path_on_failure\nfrom pre_commit.util import cmd_output\n\n\nENVIRONMENT_DIR = 'py_env'\n\n\ndef bin_dir(venv):\n    \"\"\"On windows there's a different directory for the virtualenv\"\"\"\n    bin_part = 'Scripts' if os.name == 'nt' else 'bin'\n    return os.path.join(venv, bin_part)\n\n\ndef get_env_patch(venv):\n    return (\n        ('PYTHONHOME', UNSET),\n        ('VIRTUAL_ENV', venv),\n        ('PATH', (bin_dir(venv), os.pathsep, Var('PATH'))),\n    )\n\n\ndef _find_by_py_launcher(version):  # pragma: no cover (windows only)\n    if version.startswith('python'):\n        try:\n            return cmd_output(\n                'py', '-{}'.format(version[len('python'):]),\n                '-c', 'import sys; print(sys.executable)',\n            )[1].strip()\n        except CalledProcessError:\n            pass\n\n\ndef _get_default_version():  # pragma: no cover (platform dependent)\n    def _norm(path):\n        _, exe = os.path.split(path.lower())\n        exe, _, _ = exe.partition('.exe')\n        if find_executable(exe) and exe not in {'python', 'pythonw'}:\n            return exe\n\n    # First attempt from `sys.executable` (or the realpath)\n    # On linux, I see these common sys.executables:\n    #\n    # system `python`: /usr/bin/python -> python2.7\n    # system `python2`: /usr/bin/python2 -> python2.7\n    # virtualenv v: v/bin/python (will not return from this loop)\n    # virtualenv v -ppython2: v/bin/python -> python2\n    # virtualenv v -ppython2.7: v/bin/python -> python2.7\n    # virtualenv v -ppypy: v/bin/python -> v/bin/pypy\n    for path in {sys.executable, os.path.realpath(sys.executable)}:\n        exe = _norm(path)\n        if exe:\n            return exe\n\n    # Next try the `pythonX.X` executable\n    exe = 'python{}.{}'.format(*sys.version_info)\n    if find_executable(exe):\n        return exe\n\n    if _find_by_py_launcher(exe):\n        return exe\n\n    # Give a best-effort try for windows\n    if os.path.exists(r'C:\\{}\\python.exe'.format(exe.replace('.', ''))):\n        return exe\n\n    # We tried!\n    return C.DEFAULT\n\n\ndef get_default_version():\n    # TODO: when dropping python2, use `functools.lru_cache(maxsize=1)`\n    try:\n        return get_default_version.cached_version\n    except AttributeError:\n        get_default_version.cached_version = _get_default_version()\n        return get_default_version()\n\n\ndef _sys_executable_matches(version):\n    if version == 'python':\n        return True\n    elif not version.startswith('python'):\n        return False\n\n    try:\n        info = tuple(int(p) for p in version[len('python'):].split('.'))\n    except ValueError:\n        return False\n\n    return sys.version_info[:len(info)] == info\n\n\ndef norm_version(version):\n    if os.name == 'nt':  # pragma: no cover (windows)\n        # first see if our current executable is appropriate\n        if _sys_executable_matches(version):\n            return sys.executable\n\n        # Try looking up by name\n        version_exec = find_executable(version)\n        if version_exec and version_exec != version:\n            return version_exec\n\n        version_exec = _find_by_py_launcher(version)\n        if version_exec:\n            return version_exec\n\n        # If it is in the form pythonx.x search in the default\n        # place on windows\n        if version.startswith('python'):\n            return r'C:\\{}\\python.exe'.format(version.replace('.', ''))\n\n    # Otherwise assume it is a path\n    return os.path.expanduser(version)\n\n\ndef py_interface(_dir, _make_venv):\n    @contextlib.contextmanager\n    def in_env(prefix, language_version):\n        envdir = prefix.path(helpers.environment_dir(_dir, language_version))\n        with envcontext(get_env_patch(envdir)):\n            yield\n\n    def healthy(prefix, language_version):\n        with in_env(prefix, language_version):\n            retcode, _, _ = cmd_output(\n                'python', '-c',\n                'import ctypes, datetime, io, os, ssl, weakref',\n                retcode=None,\n            )\n        return retcode == 0\n\n    def run_hook(hook, file_args):\n        with in_env(hook.prefix, hook.language_version):\n            return helpers.run_xargs(hook, helpers.to_cmd(hook), file_args)\n\n    def install_environment(prefix, version, additional_dependencies):\n        additional_dependencies = tuple(additional_dependencies)\n        directory = helpers.environment_dir(_dir, version)\n\n        env_dir = prefix.path(directory)\n        with clean_path_on_failure(env_dir):\n            if version != C.DEFAULT:\n                python = norm_version(version)\n            else:\n                python = os.path.realpath(sys.executable)\n            _make_venv(env_dir, python)\n            with in_env(prefix, version):\n                helpers.run_setup_cmd(\n                    prefix, ('pip', 'install', '.') + additional_dependencies,\n                )\n\n    return in_env, healthy, run_hook, install_environment\n\n\ndef make_venv(envdir, python):\n    env = dict(os.environ, VIRTUALENV_NO_DOWNLOAD='1')\n    cmd = (sys.executable, '-mvirtualenv', envdir, '-p', python)\n    cmd_output(*cmd, env=env, cwd='/')\n\n\n_interface = py_interface(ENVIRONMENT_DIR, make_venv)\nin_env, healthy, run_hook, install_environment = _interface\n", "path": "pre_commit/languages/python.py"}]}