【问题标题】:Pip Install SHAP Failed in Pip Virtual Environment在 Pip 虚拟环境中 Pip 安装 SHAP 失败
【发布时间】:2020-07-08 01:16:28
【问题描述】:

我在 Linux 服务器上使用 Python 3.6.3 上的 pip 虚拟环境。

我尝试 pip 安装 SHAP 但遇到以下错误:

          Building wheel for shap (setup.py) ... error
      ERROR: Complete output from command XXXX/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-aq97v0m2/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 /tmp/pip-wheel-v9vyt50m --python-tag cp36:
      ERROR: running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.6
      creating build/lib.linux-x86_64-3.6/shap
      copying shap/common.py -> build/lib.linux-x86_64-3.6/shap
      copying shap/__init__.py -> build/lib.linux-x86_64-3.6/shap
      copying shap/datasets.py -> build/lib.linux-x86_64-3.6/shap
      creating build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/pytree.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/deep.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/sampling.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/mimic.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/__init__.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/linear.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/gradient.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/explainer.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/kernel.py -> build/lib.linux-x86_64-3.6/shap/explainers
      copying shap/explainers/tree.py -> build/lib.linux-x86_64-3.6/shap/explainers
      creating build/lib.linux-x86_64-3.6/shap/explainers/other
      copying shap/explainers/other/random.py -> build/lib.linux-x86_64-3.6/shap/explainers/other
      copying shap/explainers/other/__init__.py -> build/lib.linux-x86_64-3.6/shap/explainers/other
      copying shap/explainers/other/coefficent.py -> build/lib.linux-x86_64-3.6/shap/explainers/other
      creating build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/colors.py -> build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/image.py -> build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/dependence.py -> build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/summary.py -> build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/__init__.py -> build/lib.linux-x86_64-3.6/shap/plots
      copying shap/plots/force.py -> build/lib.linux-x86_64-3.6/shap/plots
      creating build/lib.linux-x86_64-3.6/shap/benchmark
      copying shap/benchmark/plots.py -> build/lib.linux-x86_64-3.6/shap/benchmark
      copying shap/benchmark/__init__.py -> build/lib.linux-x86_64-3.6/shap/benchmark
      copying shap/benchmark/methods.py -> build/lib.linux-x86_64-3.6/shap/benchmark
      copying shap/benchmark/scorers.py -> build/lib.linux-x86_64-3.6/shap/benchmark
      copying shap/benchmark/metrics.py -> build/lib.linux-x86_64-3.6/shap/benchmark
      creating build/lib.linux-x86_64-3.6/shap/plots/resources
      copying shap/plots/resources/logoSmallGray.png -> build/lib.linux-x86_64-3.6/shap/plots/resources
      copying shap/plots/resources/bundle.js -> build/lib.linux-x86_64-3.6/shap/plots/resources
      running build_ext
      numpy.get_include() /usr/local/share/anaconda/anaconda3-5.0.1/lib/python3.6/site-packages/numpy/core/include
      building 'shap._cext' extension
      creating build/temp.linux-x86_64-3.6
      creating build/temp.linux-x86_64-3.6/shap
      gcc -pthread -B /usr/local/share/anaconda/anaconda3-5.0.1/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/XXX/include -I/usr/local/share/anaconda/anaconda3-5.0.1/include/python3.6m -I/usr/local/share/anaconda/anaconda3-5.0.1/lib/python3.6/site-packages/numpy/core/include -c shap/_cext.cc -o build/temp.linux-x86_64-3.6/shap/_cext.o
      gcc: error trying to exec 'cc1plus': execvp: No such file or directory
      error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for shap
  Running setup.py clean for shap
Failed to build shap
Installing collected packages: shap
  Running setup.py install for shap ... error

我浏览了一些类似的问题,并尝试通过指定包版本来安装 SHAP,但没有任何成功。

你能给我建议吗?提前致谢!

【问题讨论】:

  • 操作系统?错误的全文?
  • 这是在 Linux 服务器上并且更新了完整的错误!谢谢!

标签: python pip virtual-environment shap


【解决方案1】:

导致安装崩溃的错误是:

error trying to exec 'cc1plus': execvp: No such file or directory

可以通过安装 g++ 来修复:

sudo apt-get install g++

如果显示如下消息:找不到包,请尝试以下命令:

sudo apt-get update && sudo apt-get upgrade
sudo apt-get install g++

【讨论】:

  • 我实际上在这台服务器上没有 sudo 权限。有什么替代方案吗?谢谢!