0

Tried to install Shapley package (available in R) using

install shap

but got an error:

Building wheels for collected packages: shap, iml
Running setup.py bdist_wheel for shap ... error
Complete output from command C:\Users\Toly_Novik\Anaconda3\python.exe -u -c     "import setuptools, tokenize;__file__='C:\\Users\\TOLY_N~1\\AppData\\Local\\Temp  \\pip-install-o0p96nl3\\shap\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\TOLY_N~1\AppData\Local\Temp\pip-wheel-538qnmm2 --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\shap
copying shap\datasets.py -> build\lib.win-amd64-3.6\shap
copying shap\plots.py -> build\lib.win-amd64-3.6\shap
copying shap\__init__.py -> build\lib.win-amd64-3.6\shap
creating build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\ime.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\kernel.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\mimic.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\pytree.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\tree.py -> build\lib.win-amd64-3.6\shap\explainers
copying shap\explainers\__init__.py -> build\lib.win-amd64-3.6 \shap\explainers
running build_ext
numpy.get_include() C:\Users\Toly_Novik\Anaconda3\lib\site-packages\numpy\core\include
building 'shap._cext' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual  C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

Same story for install xgboost

Toly
  • 2,981
  • 8
  • 25
  • 35

3 Answers3

4

Are you trying to install shap - a library for explaining Machine Learning models? If so use

pip install shap

See the shap documentation for more info: https://pypi.org/project/shap/

Amos Long
  • 845
  • 11
  • 14
  • 2
    right answer, shapely is some geo package, shap is for machine learning. I installed it on windows using conda. – brian Jun 27 '19 at 19:38
  • I tried installing shap with pip as well as conda but later on , while importing shap i get a bunch of errors. Specifically a type error: an integer is required (got type bytes) Any suggestions please? – yash Jun 21 '21 at 09:19
  • Check out the answers on this post: https://stackoverflow.com/questions/58700384/how-to-fix-typeerror-an-integer-is-required-got-type-bytes-error-when-tryin – Amos Long Jun 22 '21 at 02:11
  • 1
    conda install -c conda-forge shap – Sachin Mar 23 '23 at 08:40
1

Did you meant 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


To install xgboost see http://xgboost.readthedocs.io/en/latest/python/python_intro.html For this you might need gcc (c/c++ compiler) or equivalent Microsoft alternative.

For xgboost with conda you can see this stackoverflow.com/questions/35139108/… or simply do conda install py-xgboost

Umang Gupta
  • 15,022
  • 6
  • 48
  • 66
  • got error File "C:\Users\TOLY_N~1\AppData\Local\Temp\pip-install-qm2tsp1b\shapely\shapely\_buildcfg.py", line 200, in lgeos = CDLL("geos_c.dll") File "C:\Users\Toly_Novik\Anaconda3\lib\ctypes\__init__.py", line 348, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found – Toly Jun 07 '18 at 02:27
  • I guess you are using windows. See note for windows `Installing Shapely 1.6 Windows users have two good installation options: the wheels at http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and the Anaconda platform’s [conda-forge](https://conda-forge.github.io/) channel.` – Umang Gupta Jun 07 '18 at 02:37
  • You can download the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely and do `pip install ` – Umang Gupta Jun 07 '18 at 02:40
  • Ok sorry, I see from your error message that you are using anaconda. So you can also do `conda config --add channels conda-forge ` and `conda install shapely` – Umang Gupta Jun 07 '18 at 02:42
  • For xgboost with conda you can see this https://stackoverflow.com/questions/35139108/how-to-install-xgboost-in-anaconda-python-windows-platform or simply do `conda install xgboost` ;) – Umang Gupta Jun 07 '18 at 02:53
  • @umang_gupta - This is what I got when tried to install xgboost: Solving environment: failed PackagesNotFoundError: The following packages are not available from current channels: - xgboost Current channels: - https://conda.anaconda.org/conda-forge/win-64 - https://conda.anaconda.org/conda-forge/noarch - https://conda.anaconda.org/anaconda-fusion/win-64 I had to delete some channels due to comment length limitations – Toly Jun 28 '18 at 02:09
  • Thanks for informing, I have updated the answer you pointed on other post. – Umang Gupta Jun 28 '18 at 03:31
  • kindly do not follow this answer. this is for a geo package called shapely. for issues installing shap due to visual studio not available you would need to install the same – Varun Rajan May 06 '20 at 12:29
  • SHAP is short for SHapley Additive exPlanations. – Long Feb 18 '21 at 13:18
0
pip install git+https://github.com/slundberg/shap.git 

Using the pip install only, did not work for me (errors running tests), neither did the conda approach.

3xCh1_23
  • 1,491
  • 1
  • 20
  • 39