rich icon indicating copy to clipboard operation
rich copied to clipboard

[BUG] Cannot access `console` after importing rich

Open squidarth opened this issue 1 year ago • 2 comments

  • [x] I've checked docs and closed issues for possible solutions.
  • [x] I can't find my issue in the FAQ.

Describe the bug

On rich version 13.4.2, I'm seeing the following issue:


In [1]: import rich

In [2]: rich.console
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [2], line 1
----> 1 rich.console

AttributeError: module 'rich' has no attribute 'console'

To import the console module one has to import it like this:

from rich.console import Console

Prior to April 30, 2024, this used to work, on the same version of rich. Did something change with that version?

Platform

Click to expand

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

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

Rich Environment:

python -m rich.diagnose
pip freeze | grep rich
╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── <class 'rich.console.Console'> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ A high level console interface.                                                                                                                                                                                                                                            │
│                                                                                                                                                                                                                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=362 ColorSystem.TRUECOLOR>                                                                                                                                                                                                                              │ │
│ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                                                                                                                                                                                            │
│     color_system = 'truecolor'                                                                                                                                                                                                                                             │
│         encoding = 'utf-8'                                                                                                                                                                                                                                                 │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>                                                                                                                                                                                           │
│           height = 79                                                                                                                                                                                                                                                      │
│    is_alt_screen = False                                                                                                                                                                                                                                                   │
│ is_dumb_terminal = False                                                                                                                                                                                                                                                   │
│   is_interactive = True                                                                                                                                                                                                                                                    │
│       is_jupyter = False                                                                                                                                                                                                                                                   │
│      is_terminal = True                                                                                                                                                                                                                                                    │
│   legacy_windows = False                                                                                                                                                                                                                                                   │
│         no_color = False                                                                                                                                                                                                                                                   │
│          options = ConsoleOptions(size=ConsoleDimensions(width=362, height=79), legacy_windows=False, min_width=1, max_width=362, is_terminal=True, encoding='utf-8', max_height=79, justify=None, overflow=None, no_wrap=False, highlight=None, markup=None, height=None) │
│            quiet = False                                                                                                                                                                                                                                                   │
│           record = False                                                                                                                                                                                                                                                   │
│         safe_box = True                                                                                                                                                                                                                                                    │
│             size = ConsoleDimensions(width=362, height=79)                                                                                                                                                                                                                 │
│        soft_wrap = False                                                                                                                                                                                                                                                   │
│           stderr = False                                                                                                                                                                                                                                                   │
│            style = None                                                                                                                                                                                                                                                    │
│         tab_size = 8                                                                                                                                                                                                                                                       │
│            width = 362                                                                                                                                                                                                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Environment Variables ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ {'TERM': 'xterm-256color', 'COLORTERM': 'truecolor', 'CLICOLOR': None, 'NO_COLOR': None, 'TERM_PROGRAM': 'iTerm.app', 'COLUMNS': None, 'LINES': None, 'JUPYTER_COLUMNS': None, 'JUPYTER_LINES': None, 'JPY_PARENT_PID': None, 'VSCODE_VERBOSE_LOGGING': None} │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
platform="Darwin"
rich==13.4.2
rich-click==1.6.1
from rich.diagnose import report
report()

squidarth avatar May 01 '24 18:05 squidarth

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar May 01 '24 18:05 github-actions[bot]

rich is the package and console is a module.

from rich.console import Console imports the class defined in that module.

I'm not sure what you expected?

TomJGooding avatar May 01 '24 19:05 TomJGooding

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

github-actions[bot] avatar Aug 26 '24 15:08 github-actions[bot]