rich: [BUG] Coloring does not work in PyCharm

Just checked - it seems to be a PyCharm problem, I will report it there, so this report is just FYI for rich users who use PyCharm. It works in the PyCharm terminal (command line), but not inside the stdout pane of PyCharm.

Reproduction Replace print() statement with console.print(string, style=‘bold red’). The string is printed, but no coloring.

from rich.console import Console
console = Console()
console.print('==> Mismatches were found in one or more platforms <==', style='bold red')

Windows 10, PyCharm Community (lastest), Python 3.8, Rich 5.0.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 19

Most upvoted comments

Not without breaking things for other users.

Interesting. That suggest the stdout window is not an embedded console. Rich will disable color if it detects it is not connected to a real terminal.

You could try this:

console = Console(color_system="windows")

That will force Rich to write color, but if PyCharm can’t handle it, you may end up with garbage.

Hi, In PyCharm 2022.1.3 seems there is no emulate terminal in output console for run configurations. Still have that problem with red logs in the console. Does anyone know how to solve this problem?

Hi Will, Here is the answer I got from PyCharm: “Hi, have you tried to enable emulate terminal in output console option in run/debug configuration? This should do the trick.” It seems that the non-terminal behavior is the default in PyCharm. IMHO, it’s worth mentioning in the rich documentation, perhaps under ‘known issues’. Unfortunately, I don’t have time to submit a PR for that. Keep up the good work! Amir

I’m also unable to make this work in PyCharm in Windows, and unsure how to apply Will’s suggestion:

console = Console(color_system=“windows”)

FYI, per https://youtrack.jetbrains.com/issue/PY-29204 it looks IntelliJ removed this feature. There is no such option in version 2021.2.3 and no indication of when it will come back. Are there any other workarounds?

I filed a new bug report at https://youtrack.jetbrains.com/issue/PY-51507

Just FYI, bug was accepted by PyCharm: Issue PY-43860

Thanks - it works. Since I only use Windows for this project, this workaround is good enough. Should I submit a bug to PyCharm?