question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Non-ASCII output hangs execution in PyInstaller packaged app

See original GitHub issue
  • [Windows 10] OS
  • [3.7.3 ] Python Version
  • [1.0.3] Gooey Version
  • [3.5] PyInstaller

Hi, I’m having problem with running Gooey app packaged with PyInstaller. App prints some outputs to multi line textbox in “execution screen” but then hangs. App runs with no issues when running it non-packaged. I dug into it and appears the problem is with further printing to multi line box.

Traceback:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "threading.py", line 917, in _bootstrap_inner
  File "threading.py", line 865, in run
  File "lib\site-packages\gooey\gui\processor.py", line 71, in _forward_stdout
  File "lib\site-packages\gooey\gui\processor.py", line 84, in _extract_progress
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 16: invalid continuation byte

Changing stdout to the following fixed the problem:

utf8_stdout = os.fdopen(sys.stdout.fileno(), mode='w', encoding='utf-8', closefd=False)
sys.stdout = utf8_stdout

The issue seems to be related to this closed issue #230

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

10reactions
maxhazcommented, Jan 24, 2020

Following this great resource, it seems that using the codecs module to redirect stdout and stderr works.

  1. Forget about the modification of processor.py
  2. Add near the top of your (main) script:
import codecs

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')

If this works for you, that could be the solution.

2reactions
Jakkwjcommented, Jan 3, 2022

https://github.com/chriskiehl/Gooey/issues/520#issuecomment-576155188

For what it worth, here is the work around I found.

In Lib>site-packages>gooey>gui>processor.py, I added import local near the top of the file, and I replaced in __init__:

self.encoding = encoding

by

self.encoding = locale.getpreferredencoding().

The purpose is to by-pass the Gooey encoding setting and force to use the local system encoding for stdin and stdout when creating the subprocess.

(Note that other ways to get the system encoding, namely sys.getdefaultencoding(), sys.getfilesystemencoding(), sys.stdout.encoding, sys.stdin.encoding do not seem to work when used with pyinstaller, probably because pyinstaller freeze their value to the ‘dev machine’ system encoding instead of allowing to use the target machine system encoding)

To build one file with pyinstaller -F -w gui.py, this is the only way to solve my problem, as I am using: [Windows 7] OS [3.8.6 ] Python Version [ 1.0.8.1] Gooey Version [ 4.7] PyInstaller Version

BTW, it should be import locale

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Spec Files - PyInstaller
In the most simple case, set the current directory to the location of your program myscript.py and execute: pyinstaller myscript.py.
Read more >
how can i convert my file to exe using pyinstaller
PyInstaller do not support non-ascii characters in paths and file names well, I personally avoid them. Then try to build exe. Share command...
Read more >
PyInstaller Documentation - Read the Docs
Open a command prompt/shell window, and navigate to the directory where your .py file is located, then build your app with the following...
Read more >
pyinstaller 3.1.1 - PyPI
It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of...
Read more >
Using PyInstaller to Easily Distribute Python Applications
In this step-by-step tutorial, you'll learn how to use PyInstaller to turn your Python application into an executable with no dependencies or installation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found