Never use print() to debug again: inspect variables, expressions, and program execution with a single, simple function call. IceCream is a Python library that makes debugging effortless and more readable. It's currently at version 2.2.0 and has an active release cadence with frequent minor updates.
pip install icecreamVerified import paths — ran on the pinned version, not inferred.
Import `ic` and use it to wrap variables or expressions for detailed output, including variable names, values, and context. Call `ic()` without arguments to log filename, line number, and function name. `ic.disable()` and `ic.enable()` can control output globally.
Ensure your project uses Python 3.9 or newer to maintain compatibility with recent IceCream versions.
Always pass a keyword argument to `configureOutput()`, e.g., `ic.configureOutput(includeContext=True)` or `ic.configureOutput(prefix='DBG| ')`.
Use `ic.configureOutput(includeContext=True, contextAbsPath=True)` to enable absolute path output.
Upgrade to IceCream v2.1.6 or newer to benefit from improved pretty-printing that gracefully handles unorderable keys. If upgrading is not possible, custom `argToStringFunction` may be needed.
Call `ic.disable()` at the entry point of your application or conditionally based on an environment variable (`if os.environ.get('DEBUG') == 'false': ic.disable()`). Remember to `ic.enable()` if you want output again.Install the module using 'pip install icecream'.
Import the function with 'from icecream import ic'.
Ensure that 'ic()' is called with at least one argument, e.g., 'ic(variable)'.
Add 'from icecream import ic' at the top of your Python file where 'ic()' is used.
For basic usage, use 'from icecream import ic' instead. If project-wide global availability is strictly required, ensure your 'icecream' installation is up-to-date and correctly installed (e.g., via 'pip install icecream'). Then, call 'install()' once at the application's entry point, typically after 'from icecream import install'.