{"id":8444,"library":"pretty-errors","title":"PrettyErrors","description":"PrettyErrors is a Python library designed to make Python exception output more legible and user-friendly. It provides color coding, simplifies tracebacks, and categorizes errors, making it easier for developers to understand what went wrong and how to fix it. The current version is 1.2.25. Its release cadence is irregular, with updates typically driven by new features or bug fixes rather than a strict schedule.","status":"active","version":"1.2.25","language":"en","source_language":"en","source_url":"https://github.com/onelivesleft/PrettyErrors/","tags":["error handling","debugging","traceback","formatting","cli","developer tool"],"install":[{"cmd":"pip install pretty_errors","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"This import activates PrettyErrors for runtime exceptions within the current script. For universal activation (including SyntaxErrors), it is recommended to run 'python -m pretty_errors' once.","symbol":"pretty_errors","correct":"import pretty_errors"}],"quickstart":{"code":"import pretty_errors\n\n# Optional: Configure pretty_errors for customized output\npretty_errors.configure(\n    separator_character = '#',\n    filename_display = pretty_errors.FILENAME_EXTENDED,\n    line_number_first = True,\n    display_link = True,\n    lines_before = 3,\n    lines_after = 2,\n    line_color = pretty_errors.RED + '> ' + pretty_errors.default_config.line_color,\n    code_color = ' ' + pretty_errors.default_config.line_color,\n    truncate_code = True,\n    display_locals = True\n)\n\ndef calculate_division(numerator, denominator):\n    return numerator / denominator\n\n# This will intentionally cause a ZeroDivisionError\nprint(calculate_division(10, 0))","lang":"python","description":"This quickstart demonstrates how to import and optionally configure `pretty_errors` to format exception output. It then triggers a `ZeroDivisionError` to show the prettified traceback. For universal activation across all Python runs (including `SyntaxError`), run `python -m pretty_errors` in your terminal once after installation."},"warnings":[{"fix":"Use a terminal emulator that supports ANSI color codes. If a monochrome terminal is necessary, call `pretty_errors.mono()` after importing `pretty_errors` to optimize output for it, or configure colors manually to be empty strings.","message":"PrettyErrors requires a terminal capable of color output to display colored exceptions effectively. On Windows, this means using PowerShell, Cmder, or similar; the standard `cmd.exe` may not render colors correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For universal formatting, including `SyntaxError`s, activate `pretty-errors` at Python startup by running `python -m pretty_errors` in your terminal once. This sets up your Python environment to include `pretty-errors` automatically.","message":"Manually importing `pretty_errors` (e.g., `import pretty_errors`) within your script will not format `SyntaxError` exceptions, as these occur before script execution. Only runtime exceptions will be prettified this way.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If conflicts arise, consider conditionally activating `pretty_errors` using `pretty_errors.activate()` within your code, or set the `PYTHON_PRETTY_ERRORS_ISATTY_ONLY` environment variable to '1' to only activate `pretty_errors` in interactive terminal sessions.","message":"PrettyErrors hooks into Python's exception handling system. This can potentially interfere with other libraries that also modify stack traces or exception reporting, leading to unexpected behavior or conflicts.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure you are using a color-capable terminal (e.g., PowerShell, Cmder, VS Code terminal). If running in a monochrome environment, call `pretty_errors.mono()` after importing `pretty_errors` or configure colors manually to be empty strings.","cause":"The terminal emulator does not support ANSI color codes, or `pretty-errors` is configured for color output in a monochrome environment.","error":"PrettyErrors traceback appears, but without any colors, or output is garbled."},{"fix":"Activate `pretty-errors` universally by running `python -m pretty_errors` in your terminal once. This configures Python's startup procedure to include `pretty-errors`, allowing it to handle `SyntaxError` exceptions before your script even runs.","cause":"The `pretty-errors` library was imported manually within the script, or was not activated universally at Python startup.","error":"SyntaxError: invalid syntax (or similar syntax error) is not formatted by pretty-errors."},{"fix":"Ensure `import pretty_errors` is one of the *very first* imports in your main script. Alternatively, for universal activation across all Python invocations, run `python -m pretty_errors` once to configure your Python environment.","cause":"The `pretty_errors` module was not imported or activated, or it was imported too late in the script after another library took over exception handling.","error":"PrettyErrors is not active when running my script, or standard Python tracebacks are shown."}]}