shap
shap copied to clipboard
cannot import name '_cext' !!
Hi there, I am really struggling to get SHAP to work and was hoping someone might be able to help me. This has been an incredibly painful process.
- So, I start by cloning the repository: ! git clone git://github.com/slundberg/shap.git shap1
- Then, in order to complete the installation, I went: ! python setup.py build How do you know if the build was successful? Mine starts out ok, but then I get the following issue/warning message halfway through:
building 'shap._cext' extension creating build/temp.linux-x86_64-3.5 creating build/temp.linux-x86_64-3.5/shap gcc -pthread -B /usr/local/envs/py3env/compiler_compat -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/envs/py3env/include/python3.5m -I/usr/local/envs/py3env/lib/python3.5/site-packages/numpy/core/include -c shap/_cext.cc -o build/temp.linux-x86_64-3.5/shap/_cext.o cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ g++ -pthread -shared -L/usr/local/envs/py3env/lib -B /usr/local/envs/py3env/compiler_compat -Wl,-rpath=/usr/local/envs/py3env/lib,--no-as-needed build/temp.linux-x86_64-3.5/shap/_cext.o -o build/lib.linux-x86_64-3.5/shap/_cext.cpython-35m-x86_64-linux-gnu.so
Notice the cc1plus warning up there - I have no idea what this means or what is going on. I am not sure if the installation has finished, having seen such a message, but I suspect not.
- When I try to run shapley.TreeExplainer(XGBmodel) I see this message right at the top (right away): C extension was not built during install! Then I get the error at the bottom cannot import name '_cext' .
I am guessing this all has something to do with the cextension not being built, but I have no idea what is going on and am very frustrated. Any help or insight would be very much appreciated. Thanks!!
And the build stops after that block of code I pasted above. I see no message about completely installed shap or anything like that. It just stops after the cc1plus error
Have you tried installing the c compiler? If you are on Ubuntu, try uninstalling shap
, running sudo apt update
and sudo apt install build-essential
and then installing shap
again.
I have similar issue, except that i didn't install SHAP library due to permission issues.
When I try to run shap.TreeExplainer it fails to import _cext straight away.
Is there a way to solve this issue without installing anything?
The exact message I get is "cannot import name _cext from shap. Thank you
Hey, I'm also having the same issue.
ImportError: cannot import name '_cext_gpu'
Using cuda10.1, nvcc is available in the PATH.
I have tried to use the shap package extracting from the .egg. It contains "_cext_gpu.py" file. Still it shows the above error.
Any clarity on the gcc/g++ and build tools versions to build the package?
Any resolution available for this?
Hiyah, I am having the same problem, has anyone found a fix?
Sampe problem here, but only with GPUTreeExplainer
Also have the problem in GPUTreeExplainer - I compiled from source using 'python setup.py install' and it found CUDA... seemed to install fine.
C extension was not built during install! ImportError: cannot import name '_cext' from partially initialized module 'shap' (most likely due to a circular import)
I facing the same problem with GPUTreeExplainer
Also have the problem in GPUTreeExplainer - I compiled from source using 'python setup.py install' and it found CUDA... seemed to install fine.
C extension was not built during install! ImportError: cannot import name '_cext' from partially initialized module 'shap' (most likely due to a circular import)
Same problem here, did anyone solve it?
Same problem here. I tried installing with pip install shap
and pip install git+https://github.com/slundberg/[email protected]
. Either way, when I run the code:
explainer = shap.GPUTreeExplainer(classifier)
shap_values = explainer.shap_values(X)
I get the error:
cannot import name '_cext_gpu' from partially initialized module 'shap' (most likely due to a circular import)
@adkinsty did you solved? Same Issue here
@davidmacar no I did not solve, just moved on
Hey everyone, did anyone get any workaround on this? I have millions of records so I want use GPU version of TreeExplainer to explain shap values. Please help!
For those encountering this problem, Please try the latest released version of shap, v0.42.1 as of time of writing.
For those encountering this problem, Please try the latest released version of shap, v0.42.1 as of time of writing.
I'm facing the same issue with SHAP 0.42.1, too. Switching back to Explainer works flawlessly.
Hi @GuidoBartoli , can you provide detailed steps to reproduce the error? and please provide the system os + cpu architecture + python version as well.
I'll close this for now as the problem is fixed on recent releases. Please feel free to open a new issue (with detailed steps to reproduce the error) if you encounter it again.