Install & Compatibility
Where this runs
tested against v3.3.0 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
colored
✓ from termcolor import colored
cprint
✓ from termcolor import cprint
Demonstrates basic text coloring, background colors, text attributes (bold, underline, italic), and true color (RGB) support. It also shows how to print to `sys.stderr`.
import sys
from termcolor import colored, cprint
import os
# Basic colored text
print(colored("Hello, World!", "red"))
# Colored text with background and attributes
cprint("Hello, colorful world!", "green", "on_yellow", attrs=["bold", "underline"])
# True color (RGB) example (requires a compatible terminal and termcolor >= 3.1.0)
# You can also specify 0-255 RGB ints via a tuple for color and on_color
if os.environ.get('FORCE_COLOR', '0') == '1': # Check for forced color for consistent demo
cprint("True color text!", (100, 150, 250), (50, 60, 70), attrs=["italic"])
else:
print(colored("Italic attribute and true color (RGB) requires termcolor >= 3.3.0 and >= 3.1.0 respectively, and a compatible terminal.", "white", attrs=["dark"]))
# Print to stderr
cprint("This is an error message.", "red", attrs=["reverse"], file=sys.stderr)
Debug
Known issues
breakingTermcolor has incrementally dropped support for older Python versions. Version 3.2.0 dropped support for Python 3.9, version 2.5.0 dropped Python 3.8, and version 2.4.0 dropped Python 3.7. The current minimum required Python version is 3.10.fixEnsure your project runs on Python 3.10 or newer, or pin `termcolor` to an older version compatible with your Python environment.
affects: < 3.10
gotchaThe handling of `FORCE_COLOR`, `NO_COLOR`, and `ANSI_COLORS_DISABLED` environment variables changed in version 3.0.0. Prior to 3.0.0, empty string values for these variables might have been interpreted differently. As of 3.0.0, these variables (and `no_color`/`force_color` function parameters) are only applied when present and contain a non-empty string.fixEnsure environment variables like `NO_COLOR` are set to a non-empty string (e.g., '1' or 'true') to properly disable coloring, and be aware of the precedence order where function parameters override environment variables.
affects: < 3.0.0
gotchaNew text attributes and color modes were introduced in recent versions. The `italic` attribute was added in 3.3.0. True color (RGB tuple) support was added in version 3.1.0. Attempting to use these features with older `termcolor` versions will result in errors or lack of intended formatting.fixUpgrade to `termcolor` 3.1.0 or newer for true color support, and 3.3.0 or newer for the `italic` attribute. Ensure your terminal emulator also supports these features.
affects: < 3.1.0 (RGB), < 3.3.0 (italic)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'termcolor'
The 'termcolor' library is not installed in the current Python environment or the environment is not activated.
fixInstall the library using pip: `pip install termcolor`
ValueError: Invalid color name 'purple'
The 'colored' function was called with a color name that is not one of the 16 supported basic color names by termcolor.
fixUse one of the supported color names such as 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'grey', 'black'.
AttributeError: module 'termcolor' has no attribute 'red'
The user is attempting to access a color directly as an attribute of the 'termcolor' module instead of using the 'colored()' function.
fixUse the 'colored()' function and pass the color name as a string argument, e.g., `colored('text', 'red')`. TypeError: colored() got an unexpected keyword argument 'bg'
The 'colored' function was called with an incorrect keyword argument for specifying the background color; it expects 'on_color'.
fixUse the 'on_color' keyword argument for background colors, e.g., `colored('text', 'white', 'on_red')`. ModuleNotFoundError: No module named 'termcolor.color'
The user is attempting an incorrect import path, assuming a submodule for colors, whereas the 'colored' function is directly available from the 'termcolor' module.
fixCorrect the import statement to `from termcolor import colored`.
Upgrade
Version history
3.3.0latest on PyPI · released Dec 29, 2025
Audit
Dependencies
No dependency data recorded yet.