From 857446bb46190ad7ea64c460b6cbd71680cd79ef Mon Sep 17 00:00:00 2001 From: s-weigand Date: Mon, 14 Mar 2016 16:36:12 +0100 Subject: [PATCH] fix for #3061, only for PY3 as requested --- .../widgets/externalshell/sitecustomize.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spyderlib/widgets/externalshell/sitecustomize.py b/spyderlib/widgets/externalshell/sitecustomize.py index 7846eb22505..09b4c32fda4 100644 --- a/spyderlib/widgets/externalshell/sitecustomize.py +++ b/spyderlib/widgets/externalshell/sitecustomize.py @@ -146,6 +146,25 @@ def write(self, text): os.environ['SPYDER_PARENT_DIR'] = spyderlib_path +#============================================================================== +# Setting console encoding (otherwise Python does not recognize encoding) +# for Windows platforms +#============================================================================== +if os.name == 'nt' and PY2: + try: + import locale, ctypes + _t, _cp = locale.getdefaultlocale('LANG') + try: + _cp = int(_cp[2:]) + ctypes.windll.kernel32.SetConsoleCP(_cp) + ctypes.windll.kernel32.SetConsoleOutputCP(_cp) + except (ValueError, TypeError): + # Code page number in locale is not valid + pass + except ImportError: + pass + + #============================================================================== # Settings for our MacOs X app #==============================================================================