rich icon indicating copy to clipboard operation
rich copied to clipboard

[Help] I cannot use Rich's color printing in RUN or DEBUG of PyCharm

Open yintian710 opened this issue 4 years ago • 8 comments

Describe the bug

I cannot use Rich's color printing in RUN or DEBUG of PyCharm, but I can use it in CMD or Powershell of Windows. Is it my setting or use problem? I couldn't find the question on Google..

**platform **

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using? windows10

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich

image

This is the printout result of my Run or Debug in Pycharm image

But I can use it in Powershell image

yintian710 avatar Jun 24 '22 16:06 yintian710

PyCharm doesn't behave like a terminal by default. There is a checkbox somewhere that enables terminal emulation. Search closed issues for a solution.

willmcgugan avatar Jun 27 '22 14:06 willmcgugan

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

github-actions[bot] avatar Jun 27 '22 15:06 github-actions[bot]

Screen shot on the "Emulate terminal in output console" is here:

  • https://stackoverflow.com/a/45534743

johnthagen avatar Aug 08 '22 14:08 johnthagen

@willmcgugan are there any plans to try and get things working with the PyCharm console? It's got a lot of great features so going to a plain terminal is a big step backwards. On the other hand, it's so damn ugly and Rich is so pretty :) it would be wonderful if I could get the best of both worlds.

davidgilbertson avatar Dec 16 '22 05:12 davidgilbertson

There’s nothing I can do. The issue is with PyCharm.

willmcgugan avatar Dec 16 '22 07:12 willmcgugan

Edit: I just found the force_terminal=True option, that's good enough for me...

Original comment: Are you aware that the PyCharm console supports quite a lot of what you do with Rich? If I trick Rich into thinking it's in a terminal, the output is pretty good:

image

So if you wanted to support PyCharm, it seems like at least a decent subset of the features could be made to work, but I have no idea how much effort it would be and whether or not that's a goal of yours.

davidgilbertson avatar Dec 18 '22 23:12 davidgilbertson

does this still work for you? @davidgilbertson - i can't reproduce this on windows

pashashocky avatar Mar 21 '25 11:03 pashashocky

Yep just tried in current PyCharm and this code outputs pretty content as above.

It still only works if you make isatty return False, so that's still not handled internally by rich. I guess PyCharm support is not a priority.

This is on Windows using iPython or the Python Console in PyCharm.

import sys
import rich

sys.stdout.isatty = lambda: True


rich.print(locals())
console = rich.console.Console()
console.print("Hello, World!", style="bold red")
console.print(
    "Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i]."
)

my_list = ["foo", "bar"]
rich.inspect(my_list, methods=True)

table = rich.table.Table(show_header=True, header_style="bold magenta")
table.add_column("Date", style="dim", width=12)
table.add_column("Title")
table.add_column("Production Budget", justify="right")
table.add_column("Box Office", justify="right")
table.add_row(
    "Dec 20, 2019",
    "Star Wars: The Rise of Skywalker",
    "$275,000,000",
    "$375,126,118",
)
table.add_row(
    "May 25, 2018",
    "[red]Solo[/red]: A Star Wars Story",
    "$275,000,000",
    "$393,151,347",
)
table.add_row(
    "Dec 15, 2017",
    "Star Wars Ep. VIII: The Last Jedi",
    "$262,000,000",
    "[bold]$1,332,539,889[/bold]",
)

console.print(table)

davidgilbertson avatar Mar 22 '25 08:03 davidgilbertson