Install & Compatibility
Where this runs
tested against v2.3.2.9.dev202606151779285115 · 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.920 runs
build_error
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 13.8s · import 0.000s · 371MB
349MB installed
● package 349MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pyagrum
✓ import pyagrum as gum
✗ import pyAgrum as gum
Since pyAgrum 2.0.0, the package name follows PEP8 rules and is lowercase. Using 'pyAgrum' will result in an ImportError.
This quickstart demonstrates how to create a simple Bayesian network (the 'Water Sprinkler' example), define its topology and conditional probability tables, and perform inference with evidence. It highlights the use of `pyagrum` (lowercase) for imports and dictionary-based CPT assignments.
import pyagrum as gum
# Create a Bayesian Network
bn = gum.BayesNet("WaterSprinkler")
# Add variables
id_c = bn.add(gum.LabelizedVariable("c", "cloudy ?", 2))
id_s = bn.add(gum.LabelizedVariable("s", "sprinkler ?", 2))
id_r = bn.add(gum.LabelizedVariable("r", "rain ?", 2))
id_w = bn.add(gum.LabelizedVariable("w", "wet grass ?", 2))
# Add arcs (dependencies)
bn.addArc(id_c, id_s)
bn.addArc(id_c, id_r)
bn.addArc(id_s, id_w)
bn.addArc(id_r, id_w)
# Define Conditional Probability Tables (CPTs) using dictionaries
bn.cpt("c").fillWith([0.5, 0.5])
bn.cpt("s")[{"c": 0}] = [0.5, 0.5]
bn.cpt("s")[{"c": 1}] = [0.9, 0.1]
bn.cpt("r")[{"c": 0}] = [0.8, 0.2]
bn.cpt("r")[{"c": 1}] = [0.2, 0.8]
bn.cpt("w")[{"s": 0, "r": 0}] = [1, 0]
bn.cpt("w")[{"s": 0, "r": 1}] = [0.1, 0.9]
bn.cpt("w")[{"s": 1, "r": 0}] = [0.1, 0.9]
bn.cpt("w")[{"s": 1, "r": 1}] = [0.01, 0.99]
# Perform inference
ie = gum.LazyPropagation(bn)
ie.setEvidence({"w": 1}) # Wet grass is true
ie.makeInference()
# Get posterior probabilities
posterior_c = ie.posterior("c")
print(f"P(c|w=1): {posterior_c}")
Errors
Common errors & fixes
IOError: [pyAgrum] I/O Error: Stream states flags are not all unset
This error often occurs when attempting to save a Bayesian network or other graphical model to a file, but the specified output directory does not exist.
fixEnsure that the directory path provided to save functions (e.g., `gum.saveBN(bn, 'path/to/directory/filename.bif')`) exists before calling the function. Create the directory if it doesn't exist.
DatabaseError: [pyAgrum] Database error: The conditioning set <COL=0, RA=4, INC=0> for target node PARTNER never appears in the database.
This error typically arises during Bayesian network learning or inference when using data, especially with small datasets or specific data splits, where a particular combination of variable values (a 'conditioning set') exists in the query/test set but was never observed in the training data.
fixConsider using 'smoothing' or adding 'priors' during the learning phase (e.g., using `BNLearner.useAprioriSmoothing()`) to handle unseen combinations. Also, evaluate the representativeness of your dataset and data splitting strategy.
Upgrade
Version history
2.3.2.9.dev202606151779285115latest on PyPI · released Jun 15, 2026
Audit
Dependencies
PythonrequiredRuntime environment