Prettifies Python exception output to make it legible.
pip install pretty-errorspretty-errors
Prettifies Python exception output to make it legible. Install it with
python -m pip install pretty_errors
If you want pretty_errors to be used whenever you run a python script you must add it to your python startup procedure. You can do so easily by running:
python -m pretty_errors
This is the recommended way to use pretty_errors; apart from being simpler and universal, using it will mean SyntaxError exceptions also get formatted prettily (which doesn't work if you are manually importing pretty_errors).

If you have not installed it universally you can use it in your project simply by importing it:
import pretty_errors
Note you need to be running in a terminal capable of colour output in order to get colour output: in Windows this means powershell, cmder, etc. If you must use a monochrome terminal then you can call the helper function pretty_errors.mono(), which will set some config options in a way that is useful for monochrome output.

If you want to configure the output then use pretty_errors.configure(), pretty_errors.whitelist(), pretty_errors.blacklist(), pretty_errors.pathed_config(). For example:
import pretty_errors
pretty_errors.configure(
separator_character = '*',
filename_display = pretty_errors.FILENAME_EXTENDED,
line_number_first = True,
display_link = True,
lines_before = 5,
lines_after = 2,
line_color = pretty_errors.RED + '> ' + pretty_errors.default_config.line_color,
code_color = ' ' + pretty_errors.default_config.line_color,
truncate_code = True,
display_locals = True
)
pretty_errors.blacklist('c:/python')

Scraping STDERR
Sometimes it will be impossible for pretty_errors to utilize sys.excepthook: for instance, if you are using a framework which installs its own logging (such as uvicorn). In such cases, you can make scrape the output to instead, replacing it with its own. To do so simple call: