Gooey icon indicating copy to clipboard operation
Gooey copied to clipboard

Gooey encoding when running with pyinstaller

Open Sirorezka opened this issue 5 years ago • 4 comments

Hello,

I'm building gooey app on windows using pyinstaller with python 3.6 using gooey 1.0.2. When I run the program after building files I get error message on python encoding when trying to print in local language in console. My code and error message below. Is there a way to fix this?

import pandas as pd
import os
import sys
import re
import xlrd

from gooey import Gooey, GooeyParser


@Gooey(advanced=True,          # toggle whether to show advanced config or not 
   show_config=True,          # skip config screens all together
   program_name='Вне рамок', # Defaults to script name
   program_description="Мимо пролетел единорог",  # Defaults to ArgParse Description
   default_size=(610, 530),   # starting size of the GUI
   required_cols=1,           # number of columns in the "Required" section
   optional_cols=1,           # number of columbs in the "Optional" section
   dump_build_config=False,   # Dump the JSON Gooey uses to configure itself
   load_build_config=None,    # Loads a JSON Gooey-generated configuration
   # language = 'russian'
   )
def main():
 
    parser = GooeyParser(description="""Хотите ли вы купить хотдог?""") 
    sg = parser.add_argument_group(
                "",gooey_options={'columns':1})
    sg.add_argument('--Checkbox', 
                      widget="CheckBox",
                      help="Очень важный параметр")

    args = parser.parse_args()

    print ("Русский текст, который не кодируется")

if __name__ == "__main__":
	main()

(sam-env) C:\Users\Ivan Petrov\Desktop\201903_samolet\201905_ETL\dist\test>test.exe "test.exe" --ignore-gooey Exception in thread Thread-1: Traceback (most recent call last): File "threading.py", line 916, in _bootstrap_inner File "threading.py", line 864, in run File "site-packages\gooey\gui\processor.py", line 69, in _forward_stdout UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte

Sirorezka avatar May 23 '19 09:05 Sirorezka

solved by passing encoding='cp1251' to decorator.

But another problem arise. If I select language='russian' and encoding='cp1251' then I get abracadabra in Gooey interface instead of russian titles.

Sirorezka avatar May 23 '19 16:05 Sirorezka

@Sirorezka This is 2019. I would try to eliminate any non-unicode from your code. So specifying encoding='cp1251' is in my view a problem, not a solution. I'm not that big on unicode but I'll try to help.

My first suspicion is that you have Python 2 somewhere in the pyinstaller toolchain.

My second suspicion, and probably easier to fix : You are using a non-unicode text editor for writing your python files; and that it encodes Russian in cp1251 instead of utf-8. I think you can solve that by adding # -*- coding: <encoding-name> -*- as the first or second line of the offending file (see https://docs.python.org/3/reference/lexical_analysis.html#encoding-declarations); The better way would be to unicode compatible file editor; For example in Notepad++ you can change the encoding via Encoding menu option.

If this doesn't help, my recommendation would be to remove all non-English strings and add them one by one till you find the offender. Looking at the traceback, the error is here, so it's something printed by the non-GUI part of your app (e.g., using print) and not something created by the argparse or gooey options you provided in the description. https://github.com/chriskiehl/Gooey/blob/e598573c6519b953e0ccfc1f3663f827f8cd7e22/gooey/gui/processor.py#L69

elad-eyal avatar May 25 '19 13:05 elad-eyal

See if #520 solve your issue.

maxhaz avatar Jan 24 '20 10:01 maxhaz

maybe you can try UTF8 mode (set env PYTHONUTF8=1)

https://peps.python.org/pep-0540/

I occur same problem and use this to resolved

linroex avatar Nov 25 '22 09:11 linroex