ANSICON Python Wrapper
The `ansicon` Python library provides a wrapper to load Jason Hood's ANSICON utility, enabling ANSI escape sequences for colored text in the Windows command prompt. It is currently at version 1.89.0, with releases typically mirroring new versions of the underlying ANSICON C utility.
Common errors
-
ModuleNotFoundError: No module named 'ansicon'
cause The `ansicon` Python package has not been installed in your current environment.fixRun `pip install ansicon` to install the library. -
Colors are not showing in my Windows terminal after calling `ansicon.load()`.
cause `ANSICON.exe` was not found or failed to load. The Python wrapper only loads the executable; it doesn't install it.fixEnsure `ANSICON.exe` is downloaded from adoxa.xyz/ansicon, extracted, and placed in a directory listed in your system's PATH environment variable or in the same directory as your Python script. Verify that `ansicon.load()` returns `True`.
Warnings
- gotcha `ANSICON.exe` is required and must be manually acquired and placed in a directory accessible via PATH or the current working directory for the Python wrapper to function.
- gotcha The `ansicon` library is primarily designed for Windows operating systems to enable ANSI escape sequences in the native command prompt.
- gotcha `ansicon.load()` returns `True` on success and `False` on failure to load the underlying `ANSICON.exe` utility. Failing to check this return value can lead to silent failures where colors do not appear.
Install
-
pip install ansicon
Imports
- load
from ansicon import load
Quickstart
import ansicon
import os
# ansicon.load() attempts to find and load ANSICON.exe.
# It returns True on success and False on failure.
# For a real application, always check the return value.
if ansicon.load():
print("ANSICON loaded successfully. Colors should work in your Windows terminal.")
# Example ANSI escape sequences
print('\033[91mThis is red text\033[0m')
print('\033[92mThis is green text\033[0m')
print('\033[94mThis is blue text\033[0m')
print('\033[1mThis is bold text\033[0m')
else:
print("Failed to load ANSICON. Colors might not work.")
if os.name == 'nt':
print("On Windows, ensure ANSICON.exe is in your PATH or script's directory.")
else:
print("Not on Windows; ANSICON is not applicable. Modern terminals usually support ANSI natively.")