From a8139ebb403eb5067ea57b81a007fa119fad3029 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 1 Aug 2020 11:30:16 +1000 Subject: [PATCH] force stdout/stderr encoding to utf8 As a GUI app, Anki only uses these for debugging info, and we've been bitten numerous times in the past by bugs caused by printing Unicode when the console only supported ASCII. An ens var might have been a better approach, but Pyinstaller does not support defining them before Python is initialized from what I can tell. Latest issue: https://forums.ankiweb.net/t/crashing-anki-version-2-1-29-bbff62bf/1650 --- qt/aqt/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 803fd5691..bcf489fc5 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -24,6 +24,11 @@ from aqt.utils import locale_dir assert anki.buildinfo.buildhash == aqt.buildinfo.buildhash +# we want to be able to print unicode debug info to console without +# fear of a traceback on systems with the console set to ASCII +sys.stdout.reconfigure(encoding="utf-8") # type: ignore +sys.stderr.reconfigure(encoding="utf-8") # type: ignore + appVersion = _version appWebsite = "https://apps.ankiweb.net/" appChanges = "https://apps.ankiweb.net/docs/changes.html"