How to Install SHAP
Updated
SHAP can be installed from either PyPI or conda-forge. If you use pip, run pip install shap. If you use conda, run conda install -c conda-forge shap. Both commands install the same core library; the right choice depends on how you manage your Python environment.
Install with pip
Use this when you are working in a standard Python environment or virtual environment.
pip install shap
Expected result: pip resolves and downloads the SHAP package and its dependencies, then reports a successful installation.
Install with conda
Use this when you manage packages and environments with conda.
conda install -c conda-forge shap
Expected result: conda solves the environment, installs SHAP from the conda-forge channel, and reports the packages it added or changed.
Before you install
- Confirm you have a working Python environment. SHAP is a Python package, so it needs one.
- Decide which package manager owns that environment. Mixing pip and conda in the same environment can cause dependency conflicts, so prefer the manager you already use.
- If you are unsure which environment is active, check it before installing so SHAP lands where you expect.
After installing
Once installation succeeds, the documentation points you to several ways to start using SHAP:
- Introduction and topical overviews — background on explainable AI with Shapley values, plus notes on interpreting predictive models and explaining fairness measures.
- Examples — worked examples grouped by data type: tabular (tree-based models, linear models, neural networks, model-agnostic), text (sentiment analysis, translation, text generation, summarization, question answering, language modelling, text entailment), image (classification, captioning), and genomic (DeepExplainer genomics).
- Reference — the API reference, API examples, and the guide to migrating to the new "Explanation" API.
A practical first step is to pick the example category that matches your model and data, then follow it against your own inputs.
Common installation issues
- Wrong environment: the install succeeds but
import shapfails in your notebook or script. This usually means the package went into a different environment than the one running your code. - Manager conflicts: installing with pip into a conda-managed environment (or the reverse) can produce dependency mismatches. Stick to one manager per environment.
- Missing dependencies: if the install reports unresolved dependencies, resolve those first rather than forcing the install.
Quick reference
| Method | Command | Use when |
|---|---|---|
| PyPI (pip) | pip install shap |
You use pip or a plain virtual environment |
| conda-forge | conda install -c conda-forge shap |
You use conda to manage environments |
Both routes are documented on the SHAP documentation site under Install.