Search code examples
pythonshap

How do I install the shap module on Mac?


I am trying to install the shap package and keep getting the following error

ModuleNotFoundError: No module named 'shap'

I have typed the following into my notebook as well as terminal

!conda install -c conda-forge shap
!conda install shap  --yes

Here are the lines of the that are erroring out

!pip install shap 
import shap
explainer = shap.TreeExplainer(model)
shap_values = explainer.shap_values(X)

I am currently on a Mac


Solution

  • This about a similar issue.It may help you.

    Modules are installed using pip on OSX but not found when importing

    If the above doesn't work, Try this:

    1. uninstall and reinstall SHAP

    2. Update Numpy to the latest version, then:

      pip install git+https://github.com/slundberg/shap.git  
      

    if the above doesn't work, then maybe this:

    To install shapely (https://pypi.org/project/Shapely/)? In python, you can install shapely by doing

     pip install shapely
    

    For windows shapley can be installed by downloading .whl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and do

    pip install <name of whl file>
    

    or if you are using anaconda you can use conda-forge to get shapely

    conda config --add channels conda-forge
     conda install shapely