Search code examples
pythonimportpackageshap

Import a package doesn't return error, but doesn't work


I installed SHAP package using pip. when I'm using pip freeze I get:

...

    shap==0.40.0

...

I'm importing the package with import shap

when I check what does return shap I get:

enter image description here

If call for SHAP attribute like: shap_explainer = shap.TreeExplainer(clf) ,I get the error: AttributeError: module 'shap' has no attribute 'TreeExplainer'


Solution

  • Your python script file is called shap.py. What you are doing is actually importing your own script and not the shap module. Python first looks in the script directory for imports, and since it finds it, it stops searching and thus never finds the shap module you would need. Rename your script to something different and it should work.