pipx icon indicating copy to clipboard operation
pipx copied to clipboard

Reason behind pipx run forcing the subprocess' encoding to utf-8?

Open J3ronimo opened this issue 9 months ago • 3 comments

Hi. Today I stumbled upon a problem with pipx run, where the python tool to run prints German Umlauts like "ü". Those didn't show up correctly in the terminal, although I knew that they did when I ran the raw python scripts without pipx wrapped around.

Turns out that the reason for this lies in pipx.util, where _fix_subprocess_env sets

env["PYTHONIOENCODING"] = "utf-8"
env["PYTHONLEGACYWINDOWSSTDIO"] = "utf-8"

into the environment inherited to the subprocess, and then exec_app sets

subprocess.run( ..., encoding="utf-8")

alongside to match that.

The problem is that my German Windows terminal (cmd.exe) is not UTF-8 but CP850, therefore anything coming as utf8 from Python looks like gibberish in my terminal.

I'd like to know if there was a specific reason behind forcing the encoding here, or if anything speaks against just leaving these settings away so that Python can detect and use the encoding of the terminal, which works nicely in my case.

Thanks and cheers.

J3ronimo avatar May 21 '24 12:05 J3ronimo