pipx icon indicating copy to clipboard operation
pipx copied to clipboard

Malformed characters when using "pipx run file:[file.py]" command with Rich library

Open regiellis opened this issue 10 months ago • 1 comments

Describe the bug

When using pipx file:[file.py] on a file importing the Rich Library system the display seems to be malformed when using tables and progress bars. If I run this normally using the standard python command with the libraries installed; Both in and out of a virtualenv and on 2 different windows machine in both CMDER and Fluent Terminal...it works as expected.

python 3.11 pipx 1.5.0

I have made sure to try all the steps on the Troubleshooting page before submitting

How to reproduce

Running the script with Rich library installed using the script comment at the top of the file;

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "typer",
#   "rich",
# ]
# ///

pipx_rich_error

Expected behavior

See included screen gif

Rich output from python -m rich

Screenshot 2024-04-19 204049

regiellis avatar Apr 20 '24 00:04 regiellis

It might have something to do with the charset encoding settings of the stdout/stderr pipeline connection between console <-> pipx <-> python. I repro'd this with:

  1. richmain.py:
# /// script
# requires-python = ">=3.11"
# dependencies = [ "typer", "rich" ]
# ///
import runpy
runpy.run_module("rich.__main__", run_name="__main__")
  1. execute: pipx run file:richmain.py
  2. repro.

afterwards you can run to test this has no repro:

$cachedir = pipx environment -V PIPX_VENV_CACHEDIR
$venv = dir $cachedir -dir | sort lastmodifiedtime -descending | select -first 1
& "$venv\scripts\activate.ps1"
python -m rich

(probably need to be using Windows Terminal to support this kind of rich output)

Also see: https://github.com/pypa/pipx/issues/209

mike-clark-8192 avatar Apr 27 '24 03:04 mike-clark-8192