Colorama

raw JSON →
0.4.6 verified Tue May 12 auth: no python install: verified quickstart: verified

Colorama is a Python library that simplifies printing colored text and styles to the terminal, ensuring cross-platform compatibility, especially on Windows. The current version is 0.4.6, released on October 25, 2022. The library has a stable release cadence, with updates addressing compatibility and minor feature enhancements.

pip install colorama
error ModuleNotFoundError: No module named 'colorama'
cause The colorama library is not installed in the Python environment you are currently using, or it was installed for a different Python version than the one executing your script.
fix
Install the colorama package using pip: pip install colorama or pip3 install colorama. If using an IDE like VS Code, ensure the correct Python interpreter is selected that has colorama installed.
error AttributeError: module 'colorama' has no attribute 'init'
cause This error often occurs when `init` (or `Fore`, `Back`, `Style`) is not correctly imported from the `colorama` module, or there's a shadowing file named `colorama.py` in your project directory.
fix
Ensure you are importing init directly, for example: from colorama import init, Fore, Back, Style. Alternatively, if you import colorama, you must call colorama.init(). Also, check that you don't have a local file named colorama.py conflicting with the installed package.
error Colorama not working / no colors in Windows terminal / PowerShell / VS Code
cause On Windows, Colorama typically needs to initialize itself to convert ANSI escape codes into native Windows console API calls. If `init()` is not called, or if the terminal environment (like some older PowerShell versions or certain IDE integrated terminals) doesn't fully support ANSI escape sequences by default, colors may not display.
fix
Call colorama.init() at the beginning of your script. For persistent issues on Windows, especially older versions or specific terminals, explicitly pass convert=True to init(): init(convert=True). As of Colorama 0.4.6, just_fix_windows_console() can also be used for minimal setup.
error ImportError: cannot import name 'Fore' from 'colorama'
cause This typically happens due to a case sensitivity error, where 'fore' is used instead of 'Fore' (or 'back' instead of 'Back', 'style' instead of 'Style'). Python imports are case-sensitive.
fix
Correct the import statement to use the proper capitalization: from colorama import Fore, Back, Style.
gotcha On Windows, failing to call 'init()' may result in ANSI escape sequences being displayed as raw text instead of colored output.
fix Always call 'init()' at the start of your program to initialize Colorama.
gotcha Using 'init(autoreset=True)' resets styles after each print statement, which may not be desired in all cases.
fix Use 'init(autoreset=False)' if you prefer to manually reset styles.
gotcha Colorama's 'Style.DIM' may not be supported on all terminals, leading to inconsistent text appearance.
fix Test your application on target terminals to ensure consistent styling.
gotcha Combining Colorama with other ANSI-based libraries without proper initialization may lead to unexpected behavior.
fix Ensure Colorama is initialized before using it with other ANSI-based libraries.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.01s 18.0M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) - - 0.01s 19.8M
3.11 slim (glibc) - - 0.02s 20M
3.12 alpine (musl) - - 0.01s 11.7M
3.12 slim (glibc) - - 0.03s 12M
3.13 alpine (musl) - - 0.02s 11.3M
3.13 slim (glibc) - - 0.03s 12M
3.9 alpine (musl) - - 0.01s 17.5M
3.9 slim (glibc) - - 0.02s 18M

Initialize Colorama with auto-reset and print colored and styled text.

from colorama import init, Fore, Back, Style

init(autoreset=True)

print(Fore.RED + 'This is red text')
print(Back.GREEN + 'This has a green background')
print(Style.BRIGHT + 'This is bright text')
print('Back to normal text')