Install & Compatibility
Where this runs
tested against v0.4.2 · 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.129s · 26.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.1s · import 0.116s · 27MB
25MB installed
● package 25MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
add_hook
✓ import colored_traceback
colored_traceback.add_hook()
✗ from colored_traceback import add_hook # Direct import of add_hook is not the intended primary usage for activation.
The add_hook() function is typically called directly from the colored_traceback module to install the exception hook.
auto
✓ import colored_traceback.auto
A convenience import that automatically calls add_hook().
always
✓ import colored_traceback.always
A convenience import that automatically calls add_hook(always=True) to force color output even when stderr is piped.
This quickstart demonstrates how to activate colored tracebacks by simply importing `colored_traceback.auto`. Running this script will cause a `ZeroDivisionError` and display a colorized traceback in your terminal.
import colored_traceback.auto
def cause_error():
return 1 / 0
def main():
print("Attempting to cause an error...")
cause_error()
if __name__ == "__main__":
main()
Debug
Known issues
breakingPython 3.13 and newer versions introduce native colorized tracebacks. Using `colored-traceback` with Python 3.13+ may lead to unexpected behavior, double coloring, or conflicts with the built-in system.fixOn Python 3.13+, consider removing `colored-traceback` and relying on the interpreter's native colorization. If `colored-traceback` specific features are required, test thoroughly for conflicts or ensure native coloring is disabled if possible via `PYTHON_COLORS=0` or `NO_COLOR` environment variables.
affects: Python 3.13+
gotchaTracebacks may not appear colored when the output (stderr) is redirected or piped to another command/file.fixUse `colored_traceback.add_hook(always=True)` or `import colored_traceback.always` to force color output even when stderr is not a TTY.
affects: All versions
gotchaOn Windows, `colored-traceback` automatically installs the `colorama` package to provide ANSI escape sequence support, which might be an unexpected dependency for some users.fixEnsure `colorama` is installed if you encounter issues with coloring on Windows. If `colorama` is not desired, `colored-traceback` is not suitable for Windows environments requiring minimal dependencies.
affects: All versions on Windows
Errors
Common errors & fixes
Tracebacks appear with unexpected or double coloring on Python 3.13+.
Conflict with Python 3.13's built-in colored traceback feature.
fixRemove `colored-traceback` from your environment if using Python 3.13 or newer, or investigate methods to disable Python's native colorization if you prefer `colored-traceback`'s output.
Tracebacks are monochrome (not colored) when running my script and piping output to another tool or saving to a file.
By default, `colored-traceback` disables color output when `stderr` is not detected as an interactive terminal (TTY).
fixModify your activation call to `colored_traceback.add_hook(always=True)` or use the convenience import `import colored_traceback.always`.
AttributeError: module 'colored_traceback' has no attribute 'auto' (or 'always' or 'add_hook')
Incorrect import statement or a damaged/incomplete installation.
fixEnsure you are importing correctly as `import colored_traceback.auto`, `import colored_traceback.always`, or `import colored_traceback` followed by `colored_traceback.add_hook()`. If the issue persists, try reinstalling the package: `pip uninstall colored-traceback && pip install colored-traceback`.
Upgrade
Version history
0.4.2latest on PyPI · released Jul 13, 2024
Audit
Dependencies
pygmentsrequiredUsed for syntax highlighting the traceback output.
coloramaoptionalProvides cross-platform ANSI escape sequence support for terminals, automatically installed on Windows.