Skip to content

Commit d71699d

Browse files
authored
Merge pull request #1474 from pre-commit/unicode_error_py_launcher
avoid a UnicodeError on windows with non-charmap characters
2 parents 42562a1 + 0781dac commit d71699d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pre_commit/languages/python.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def _find_by_py_launcher(
6767
) -> Optional[str]: # pragma: no cover (windows only)
6868
if version.startswith('python'):
6969
num = version[len('python'):]
70+
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
71+
env = dict(os.environ, PYTHONIOENCODING='UTF-8')
7072
try:
71-
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
72-
return cmd_output(*cmd)[1].strip()
73+
return cmd_output(*cmd, env=env)[1].strip()
7374
except CalledProcessError:
7475
pass
7576
return None

0 commit comments

Comments
 (0)