{"id":21048,"library":"clingo","title":"clingo","description":"CFFI-based Python bindings to the clingo Answer Set Programming (ASP) solver. Version 5.8.0, released 2024-04-06. Cadence: irregular, roughly annual.","status":"active","version":"5.8.0","language":"python","source_language":"en","source_url":"https://github.com/potassco/clingo","tags":["answer set programming","ASP","solver","logic programming","potassco"],"install":[{"cmd":"pip install clingo","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"Direct class import is conventional.","wrong":"import clingo; ctl = clingo.Control()","symbol":"Control","correct":"from clingo import Control"},{"note":"Function is in clingo, not a submodule.","wrong":"from clingo.symbol import Function","symbol":"Function","correct":"from clingo import Function"}],"quickstart":{"code":"from clingo import Control\nctl = Control()\nctl.add(\"base\", [], \"a :- not b. b :- not a.\")\nctl.ground([(\"base\", [])])\nwith ctl.solve(yield_=True) as handle:\n    for model in handle:\n        print(model)\n","lang":"python","description":"Basic ASP solving: add rules, ground, and iterate over stable models."},"warnings":[{"fix":"Use the context manager: `with ctl.solve(yield_=True) as handle:` instead of `result = ctl.solve()`.","message":"From clingo 5.5 to 5.6, the `solve` method changed from returning a `SolveResult` to a `SolveHandle` with a context manager. In 5.4 and earlier, `ctl.solve()` returned a `SolveResult` directly.","severity":"breaking","affected_versions":">=5.6"},{"fix":"After the `with` block, use `handle.get()` to get satisfiability (e.g., `print(handle.get().satisfiable)`).","message":"The `clingo.solving.SolveResult` class was removed in 5.6. `solve()` now returns a `SolveHandle`, and the satisfiability is obtained via `solve()`'s return value after the context manager exits.","severity":"breaking","affected_versions":">=5.6"},{"fix":"Replace `ctl.load('file.lp')` with `with open('file.lp') as f: ctl.add('base', [], f.read()); ctl.ground([('base', [])])`.","message":"The `clingo.Control.load()` method is deprecated in 5.8 in favor of `Control.add()` + `Control.ground()`.","severity":"deprecated","affected_versions":"5.8"},{"fix":"Always use `with ctl.solve(yield_=True) as handle: for model in handle: print(model)`.","message":"Calling `Control.solve()` without `yield_=True` will not return models; you must iterate over the `SolveHandle` or use the context manager with `yield_=True`.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install via conda: `conda install -c potassco clingo`, or install from source with proper dependencies.","cause":"Clingo installed from PyPI may not work on systems without a compatible C compiler or prebuilt wheel (e.g., ARM macOS).","error":"ModuleNotFoundError: No module named 'clingo'"},{"fix":"Use `#const` directives, or ground the program properly, or avoid arithmetic on variables without domain bounds.","cause":"Using arithmetic expressions on ungrounded variables (e.g., `X = Y + 1`) without proper grounding.","error":"clingo.core.SolveError: undefined arithmetic operation"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}