From fad49027088ac43bcf4f31d151bc8b4acc91d6d6 Mon Sep 17 00:00:00 2001 From: LmeSzinc Date: Wed, 24 Jun 2020 10:49:27 +0800 Subject: [PATCH] Fix: Unable to run in pythonw.exe --- module/config/argparser.py | 12 ++++++++---- module/config/argparser_en.py | 12 ++++++++---- module/config/argparser_jp.py | 12 ++++++++---- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/module/config/argparser.py b/module/config/argparser.py index 4a677e793..cff3eb2e2 100644 --- a/module/config/argparser.py +++ b/module/config/argparser.py @@ -10,10 +10,14 @@ from module.config.dictionary import dic_chi_to_eng, dic_eng_to_chi from module.config.update import get_config from module.logger import pyw_name -if sys.stdout.encoding != 'UTF-8': - sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') -if sys.stderr.encoding != 'UTF-8': - sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') + +try: + if sys.stdout.encoding != 'UTF-8': + sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') + if sys.stderr.encoding != 'UTF-8': + sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') +except Exception: + pass @Gooey( diff --git a/module/config/argparser_en.py b/module/config/argparser_en.py index 096589654..63a83fcf2 100644 --- a/module/config/argparser_en.py +++ b/module/config/argparser_en.py @@ -10,10 +10,14 @@ from module.config.dictionary import dic_true_eng_to_eng, dic_eng_to_true_eng from module.config.update import get_config from module.logger import pyw_name -if sys.stdout.encoding != 'UTF-8': - sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') -if sys.stderr.encoding != 'UTF-8': - sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') + +try: + if sys.stdout.encoding != 'UTF-8': + sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') + if sys.stderr.encoding != 'UTF-8': + sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') +except Exception: + pass @Gooey( diff --git a/module/config/argparser_jp.py b/module/config/argparser_jp.py index a70f30c18..da08ed30f 100644 --- a/module/config/argparser_jp.py +++ b/module/config/argparser_jp.py @@ -9,10 +9,14 @@ from module.config.dictionary import dic_true_eng_to_eng, dic_eng_to_true_eng from module.config.update import get_config from module.logger import pyw_name -if sys.stdout.encoding != 'UTF-8': - sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') -if sys.stderr.encoding != 'UTF-8': - sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') + +try: + if sys.stdout.encoding != 'UTF-8': + sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') + if sys.stderr.encoding != 'UTF-8': + sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') +except Exception: + pass @Gooey(