{"id":7097,"library":"colored-traceback","title":"Colored Traceback","description":"Colored-traceback is a Python library that automatically colors uncaught exception tracebacks, aiming to improve readability in the terminal. The project is currently active, with its latest release (0.4.2) on July 13, 2024, but has an infrequent release cadence.","status":"active","version":"0.4.2","language":"en","source_language":"en","source_url":"https://www.github.com/staticshock/colored-traceback.py","tags":["traceback","color","debugging","developer-tool","error-handling"],"install":[{"cmd":"pip install colored-traceback","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for syntax highlighting the traceback output.","package":"pygments","optional":false},{"reason":"Provides cross-platform ANSI escape sequence support for terminals, automatically installed on Windows.","package":"colorama","optional":true}],"imports":[{"note":"The add_hook() function is typically called directly from the colored_traceback module to install the exception hook.","wrong":"from colored_traceback import add_hook # Direct import of add_hook is not the intended primary usage for activation.","symbol":"add_hook","correct":"import colored_traceback\ncolored_traceback.add_hook()"},{"note":"A convenience import that automatically calls add_hook().","symbol":"auto","correct":"import colored_traceback.auto"},{"note":"A convenience import that automatically calls add_hook(always=True) to force color output even when stderr is piped.","symbol":"always","correct":"import colored_traceback.always"}],"quickstart":{"code":"import colored_traceback.auto\n\ndef cause_error():\n    return 1 / 0\n\ndef main():\n    print(\"Attempting to cause an error...\")\n    cause_error()\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"On 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.","message":"Python 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.","severity":"breaking","affected_versions":"Python 3.13+"},{"fix":"Use `colored_traceback.add_hook(always=True)` or `import colored_traceback.always` to force color output even when stderr is not a TTY.","message":"Tracebacks may not appear colored when the output (stderr) is redirected or piped to another command/file.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `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.","message":"On Windows, `colored-traceback` automatically installs the `colorama` package to provide ANSI escape sequence support, which might be an unexpected dependency for some users.","severity":"gotcha","affected_versions":"All versions on Windows"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remove `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.","cause":"Conflict with Python 3.13's built-in colored traceback feature.","error":"Tracebacks appear with unexpected or double coloring on Python 3.13+."},{"fix":"Modify your activation call to `colored_traceback.add_hook(always=True)` or use the convenience import `import colored_traceback.always`.","cause":"By default, `colored-traceback` disables color output when `stderr` is not detected as an interactive terminal (TTY).","error":"Tracebacks are monochrome (not colored) when running my script and piping output to another tool or saving to a file."},{"fix":"Ensure 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`.","cause":"Incorrect import statement or a damaged/incomplete installation.","error":"AttributeError: module 'colored_traceback' has no attribute 'auto' (or 'always' or 'add_hook')"}]}