avoid a UnicodeError on windows with non-charmap characters

This commit is contained in:
Anthony Sottile
2020-05-27 13:14:29 -07:00
parent 42562a12ed
commit 0781dac78f

View File

@@ -67,9 +67,10 @@ def _find_by_py_launcher(
) -> Optional[str]: # pragma: no cover (windows only)
if version.startswith('python'):
num = version[len('python'):]
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
env = dict(os.environ, PYTHONIOENCODING='UTF-8')
try:
cmd = ('py', f'-{num}', '-c', 'import sys; print(sys.executable)')
return cmd_output(*cmd)[1].strip()
return cmd_output(*cmd, env=env)[1].strip()
except CalledProcessError:
pass
return None