Install & Compatibility
Where this runs
tested against v0.1.4.7 · 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.910 runs
build_error
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 21.4s · import 6.375s · 493MB
516MB installed
● package 516MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pc
✓ from causallearn.search.ConstraintBased.PC import pc
✗ from causal_learn.search.ConstraintBased.PC import pc
The PyPI package name `causal-learn` uses a hyphen, but the Python import name is `causallearn` (no hyphen).
ges
✓ from causallearn.search.ScoreBased.GES import ges
✗ from causal_learn.search.ScoreBased.GES import ges
The PyPI package name `causal-learn` uses a hyphen, but the Python import name is `causallearn` (no hyphen).
chisq
✓ from causallearn.utils.cit import chisq
Common conditional independence test for continuous data.
This quickstart demonstrates how to generate synthetic data, apply the PC (Peter and Clark) algorithm for causal discovery using the chi-squared conditional independence test, and print the resulting adjacency matrix representing the causal graph. The PC algorithm is a constraint-based method widely used for learning causal structures from observational data.
import numpy as np
from causallearn.search.ConstraintBased.PC import pc
from causallearn.utils.cit import chisq
# 1. Generate synthetic data: X0 -> X1 <- X2, X0 -> X2
# X0 influences X2, and both X0 and X2 influence X1
np.random.seed(42)
N = 1000
X0 = np.random.normal(0, 1, N)
X2 = X0 * 0.5 + np.random.normal(0, 1, N)
X1 = X0 * 0.3 + X2 * 0.7 + np.random.normal(0, 1, N)
data = np.array([X0, X1, X2]).T # P-dimensional data (N samples, P variables)
# 2. Run PC algorithm for causal discovery
# data: input data matrix (N_samples, N_variables)
# alpha: significance level for conditional independence test (e.g., 0.05)
# ci_test: conditional independence test function (e.g., chisq for continuous data)
# verbose: set to True for detailed progress output
# num_cores: number of cores to use for parallel computation (-1 for all available)
causal_graph = pc(data, alpha=0.05, ci_test=chisq, verbose=False, num_cores=-1)
# 3. Print the adjacency matrix of the discovered causal graph
# An entry (i, j) == 1 indicates an edge from i to j, 0 otherwise.
print("\nDiscovered Causal Graph Adjacency Matrix:")
print(causal_graph.G.graph)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'causal_learn'
Incorrect package name used in the import statement. The PyPI package name `causal-learn` is different from its Python import name `causallearn`.
fixChange your import statements from `from causal_learn import ...` to `from causallearn import ...`.
graphviz.backend.ExecutableNotFound: failed to execute dot; make sure the Graphviz executables are on your systems' path
The Graphviz command-line tools are not installed or not accessible in your system's PATH. The Python `graphviz` package is a wrapper; it requires the underlying Graphviz system tools.
fixInstall Graphviz on your operating system (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS, or download from graphviz.org for Windows) and ensure it's in your system's PATH.
ValueError: Input data must be a numpy array.
A causal-learn algorithm received input data that was not a `numpy.ndarray` or was not in the expected 2D `(n_samples, n_features)` format.
fixConvert your data to a `numpy.ndarray`. If starting from a pandas DataFrame `df`, use `data = df.values`. Ensure it has the correct shape.
Upgrade
Version history
0.1.4.7latest on PyPI · released May 18, 2026
Audit
Dependencies
numpyrequiredCore numerical operations and data structures.
scipyrequiredScientific computing, statistics, and optimization.
networkxrequiredGraph data structures and algorithms.
scikit-learnrequiredUtility functions and machine learning algorithms.
pandasrequiredData manipulation and analysis, often used for input data.
matplotlibrequiredPlotting and visualization capabilities.
tqdmrequiredProgress bars for iterative computations.
joblibrequiredLightweight pipelining for parallel computation.