Last modified: Mar 25, 2025 By Alexander Williams

How to Install Rich in Python Step by Step

Rich is a Python library for rich text and beautiful formatting in the terminal. It makes console output more readable and attractive.

This guide will walk you through installing Rich in Python. Follow these simple steps to get started.

Prerequisites

Before installing Rich, ensure you have Python installed on your system. You can check this by running:


python --version

If Python is not installed, download it from the official website. Also, ensure pip is up to date.

Install Rich Using pip

The easiest way to install Rich is using pip. Open your terminal or command prompt and run:


pip install rich

This command downloads and installs the latest version of Rich. Wait for the installation to complete.

Verify the Installation

To confirm Rich is installed correctly, run the following Python code:

 
import rich
print(rich.__version__)

If installed properly, it will display the Rich version. If you encounter an error like ModuleNotFoundError, check our guide on How To Solve ModuleNotFoundError.

Basic Usage of Rich

Rich provides many features. Here’s a simple example to print styled text:

 
from rich import print

print("[bold red]Hello[/bold red], [italic blue]World![/italic blue]")

This code prints "Hello" in bold red and "World!" in italic blue. Rich supports many styles and colors.

Using Rich Console

For more control, use the Console class. Here’s an example:

 
from rich.console import Console

console = Console()
console.print("This is a [bold green]styled[/bold green] message!")

The Console class offers advanced features like logging and progress bars.

Rich Tables

Rich can create beautiful tables. Here’s how to make one:

 
from rich.console import Console
from rich.table import Table

console = Console()

table = Table(title="Star Wars Movies")
table.add_column("Year", style="cyan")
table.add_column("Title", style="magenta")
table.add_row("1977", "Star Wars: A New Hope")
table.add_row("1980", "The Empire Strikes Back")

console.print(table)

This code creates a table with styled columns and rows. Rich tables are highly customizable.

Rich Progress Bars

Rich includes progress bars for long-running tasks. Example:

 
from rich.progress import track
import time

for _ in track(range(10), description="Processing..."):
    time.sleep(0.1)

This displays a progress bar that updates as the loop runs. It’s great for CLI applications.

Conclusion

Rich is a powerful library for enhancing terminal output in Python. It’s easy to install and use.

With Rich, you can create styled text, tables, progress bars, and more. Start using it today to make your console applications stand out.

If you face any issues, refer to the official Rich documentation or check our guide on solving ModuleNotFoundError.