Skip to content

Instantly share code, notes, and snippets.

@oleksis
Last active July 29, 2023 06:02
Show Gist options
  • Save oleksis/d1cc378d3f8fae62f15627e3bc57de7f to your computer and use it in GitHub Desktop.
Save oleksis/d1cc378d3f8fae62f15627e3bc57de7f to your computer and use it in GitHub Desktop.
Customize the Python REPL on start-up

image

pythonrc file

~/.pythonrc

import subprocess
import sys

try:
    import rich
except ModuleNotFoundError:
    print(" -- Installing rich... ", end="")

    try:
        pip_rich = [
            sys.executable,
            "-m",
            "pip",
            "install",
            "--no-cache-dir",
            "-qq",
            "--upgrade",
            "rich",
        ]
        subprocess.run(pip_rich, check=True)
    except subprocess.CalledProcessError as e:
        print(f"\n -- Error intalling rich package: {e}")
        exit(1)

    print("Done!")
    import rich

help = rich.inspect
print = rich.print
PYTHONSTARTUP=~/.pythonrc python3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment