Install & Compatibility
Where this runs
tested against v0.2.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.040s · 18MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.039s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
set_excepthook
✓ import stackprinter; stackprinter.set_excepthook()
show
✓ import stackprinter; stackprinter.show()
format
✓ import stackprinter; message = stackprinter.format()
TracePrinter
✓ from stackprinter import TracePrinter
This quickstart demonstrates two ways to use stackprinter: integrating with Python's standard logging module for automatic verbose exception logging, and manually calling `stackprinter.show()` within an `except` block for immediate, enhanced traceback output. The `set_excepthook()` method (commented out) is also available to globally replace Python's default exception printout.
import stackprinter
import logging
import sys
# Option 1: Replace the default excepthook for all uncaught exceptions
# stackprinter.set_excepthook(style='darkbg')
# Option 2: Use in a try-except block or integrate with logging
class VerboseExceptionFormatter(logging.Formatter):
def formatException(self, exc_info):
# exc_info is a tuple (type, value, traceback)
msg = stackprinter.format(exc_info, style='darkbg', source_lines=7, truncate_vals=200)
return msg
def configure_logger(logger_name=None):
formatter = VerboseExceptionFormatter('%(asctime)s %(levelname)s: %(message)s')
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(formatter)
logger = logging.getLogger(logger_name)
logger.addHandler(handler)
logger.setLevel(logging.ERROR)
return logger
logger = configure_logger('my_app')
def problematic_function(a, b):
result = a / b
return result
def main():
x = 10
y = 0
try:
problematic_function(x, y)
except ZeroDivisionError:
logger.exception('An error occurred during calculation:')
except TypeError as e:
# For manual formatting and printing
print('\n--- Manual stackprinter output ---\n')
stackprinter.show(e, style='darkbg')
if __name__ == '__main__':
main()
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'stackprinter'
The stackprinter library is not installed in your current Python environment.
fixpip install stackprinter
TypeError: install() got an unexpected keyword argument 'file'
The `install()` function in stackprinter does not directly accept a `file` argument for output redirection; output configuration is handled via a `formatter` object.
fixCreate a `Formatter` instance with your desired output and pass it to `install`: `import sys; formatter = stackprinter.Formatter(output_dest=sys.stderr); stackprinter.install(formatter=formatter)`
TypeError: default_excepthook() missing 1 required positional argument: 'etype'
The `stackprinter.default_excepthook` function is an internal handler designed to be called by `sys.excepthook` and expects three arguments (`etype`, `evalue`, `etraceback`), so it should not be called manually without them.
fixDo not call `stackprinter.default_excepthook()` directly. Instead, use `stackprinter.install()` to set it as the global exception hook, or use `stackprinter.format()` to format an exception manually.
AttributeError: module 'stackprinter' has no attribute 'print_exception'
The `stackprinter` module does not have a function named `print_exception`. The correct function to print the current exception information is `print_exc()`.
fixReplace `stackprinter.print_exception()` with `stackprinter.print_exc()`.
Upgrade
Version history
0.2.13latest on PyPI · released Apr 17, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.4 or higher.