0

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

Samantha
  • 91
  • 2
  • 7
  • Does the `conda install` call work? If you do `conda list`, can you see that shap has been installed? – FiddleStix Aug 30 '20 at 16:32
  • Yes shap and shapely have been installed – Samantha Aug 30 '20 at 16:35
  • No, conda-forge is correct. I have installed shap into a conda env, run `python` from the command line and have been able to `import shap` just fine so you need to a) restart your kernel/notebook b) check that you installed shap in the right environment and c) make sure you haven't named your folder "shap" (check for other naming conflicts too). – FiddleStix Aug 30 '20 at 16:45
  • Shap and shapely are in the current environment (base) and path `/Users/samantha.p/miniconda3` – Samantha Aug 30 '20 at 20:07
  • Just a note, shap and shapley are very different packages that do very different things. So I don't think shapely is relevant here. – slund Sep 09 '20 at 22:23

3 Answers3

2

I got same issue using pip install shap command. However, conda install worked. I use Mac.

conda install -c conda-forge shap
Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
1

I am on Mac OS Big Sur with pip 21.2.4 and Python 3.8.9. I am able to install shap with the following command.

ARCHFLAGS="-arch x86_64" pip3 install shap

Yeggy
  • 11
  • 1
0

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
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
  • Have updated my answer, the mentioned post talks about a similar issue where "Modules are installed using pip on OSX but not found when importing".I think this is the problem of alias, "two versions of python installed. If the pip that you are accessing is of one version & the python interpreter used is another."So just see Have that you are using the same version of python to install and use the package. – Jatin Mehrotra Aug 31 '20 at 01:56
  • shapely is a different package from shap. The former is for shapes, the latter is a machine learning data visualization tool. – Naomi May 12 '21 at 14:45