Better Exceptions is a Python library that automatically enhances standard Python traceback outputs, making them significantly more readable and useful for debugging. It achieves this through features like colorization, displaying more context around code lines, and printing relevant variable values at each point in the traceback. The current version is 0.3.3. It has a slow release cadence, with the last significant update (0.2.1) being several years ago, focusing on stability.
pip install better_exceptionsVerified import paths — ran on the pinned version, not inferred.
To quickly enable better-exceptions, set the `BETTER_EXCEPTIONS` environment variable to '1' and then run your Python script. The library will automatically hook into the exception handling system and format any uncaught exceptions.
Ensure `export BETTER_EXCEPTIONS=1` (or `setx BETTER_EXCEPTIONS 1` on Windows) is set in your environment before running Python. Alternatively, call `better_exceptions.hook()` after importing in your script for explicit activation.
Always unset the `BETTER_EXCEPTIONS` environment variable or remove `better_exceptions.hook()` calls when deploying to production.
If `better-exceptions` doesn't seem to be working, check for other installed packages or system configurations that might be overriding `sys.excepthook`. Uninstall or disable conflicting components if possible.
For persistent activation across sessions on Linux/OSX, add `export BETTER_EXCEPTIONS=1` to your shell's configuration file (e.g., `~/.profile`, `~/.bashrc`, or `~/.zshrc`). On Windows, use `setx BETTER_EXCEPTIONS 1` for a persistent system-wide variable.
Always verify the context of search results to ensure they refer to the Python library `better-exceptions` by checking the domain (e.g., GitHub for the Python project, PyPI) or content specific to Python development.
Install the package using pip: `pip install better-exceptions`
Set the environment variable `BETTER_EXCEPTIONS=1` before running your script (e.g., `export BETTER_EXCEPTIONS=1` on Linux/macOS or `set BETTER_EXCEPTIONS=1` on Windows). Alternatively, manually activate it at the beginning of your script with `import better_exceptions; better_exceptions.hook()`.
Manually ensure `better_exceptions.hook()` is called after other potential `sys.excepthook` modifications, or investigate if specific integrations (e.g., for Django) are needed, or if an uninstall of conflicting packages (like `python3-apport` on Ubuntu) is required.
Install the `colorama` package: `pip install colorama`. If it's already installed, try reinstalling both `colorama` and `better-exceptions`.
No dependency data recorded yet.