Skip to content

inference scripts crash on Windows when output is redirected or piped #193

Description

@Phlabry

Describe the bug
The inference scripts print check, cross and warning characters. On Windows, when stdout is redirected or piped (CI, IDE run panes, Git Bash, > file), Python encodes output with the locale code page, usually cp1252, and those characters raise UnicodeEncodeError. The error handler then raises the same exception again while trying to report it. A real console window is not affected, since Python 3.6 and later write to it as UTF-8 (PEP 528).

To Reproduce

  1. On Windows, run py inference/validate_labels.py > out.txt.
  2. It fails on the first status line with UnicodeEncodeError: 'charmap' codec can't encode character '✓'.

Expected behavior
The scripts run regardless of how output is captured.

Additional context
Setting PYTHONIOENCODING=utf-8 or PYTHONUTF8=1 works around it, which confirms the cause. A code fix would be ASCII status markers, or sys.stdout.reconfigure(encoding="utf-8") at startup. PR #177 replaces some of these in validate_labels.py but not the warning lines. generate_balanced_data.py:218-219 has the same issue. Logger calls in label_generator.py, train_model.py and test_model.py print "--- Logging error ---" tracebacks instead of crashing.

Found while writing the setup documentation in #138 / #178.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpython

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions