尝试安装 azureml-interpret 时出现多个错误

问题描述

我目前正在尝试安装 azureml-interpret,但我遇到了 shap azureml-interpret 的问题。

在运行 pip install azureml-interpret 时我得到:

ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Alex\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'C:\\Users\\Alex\\AppData\\Local\\Temp\\pip-install-k175gbg_\\shap_1e1feac0fd27463fbfcdc6216c3f4c6f\\setup.py'"'"'; __file__='"'"'C:\\Users\\Alex\\AppData\\Local\\Temp\\pip-install-k175gbg_\\shap_1e1feac0fd27463fbfcdc6216c3f4c6f\\setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' install --record 'C:\Users\Alex\AppData\Local\Temp\pip-record-bu1hm3ps\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\python39\Include\shap'
         cwd: C:\Users\Alex\AppData\Local\Temp\pip-install-k175gbg_\shap_1e1feac0fd27463fbfcdc6216c3f4c6f\
    Complete output (64 lines):

    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.9
    creating build\lib.win-amd64-3.9\shap
    copying shap\common.py -> build\lib.win-amd64-3.9\shap
    copying shap\datasets.py -> build\lib.win-amd64-3.9\shap
    copying shap\__init__.py -> build\lib.win-amd64-3.9\shap
    creating build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\bruteforce.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\explainer.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\gradient.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\kernel.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\linear.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\mimic.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\partition.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\permutation.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\pytree.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\sampling.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\tree.py -> build\lib.win-amd64-3.9\shap\explainers
    copying shap\explainers\__init__.py -> build\lib.win-amd64-3.9\shap\explainers
    creating build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\coefficent.py -> build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\lime.py -> build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\maple.py -> build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\random.py -> build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\treegain.py -> build\lib.win-amd64-3.9\shap\explainers\other
    copying shap\explainers\other\__init__.py -> build\lib.win-amd64-3.9\shap\explainers\other
    creating build\lib.win-amd64-3.9\shap\explainers\deep
    copying shap\explainers\deep\deep_pytorch.py -> build\lib.win-amd64-3.9\shap\explainers\deep
    copying shap\explainers\deep\deep_tf.py -> build\lib.win-amd64-3.9\shap\explainers\deep
    copying shap\explainers\deep\__init__.py -> build\lib.win-amd64-3.9\shap\explainers\deep
    creating build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\bar.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\colorconv.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\colors.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\decision.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\dependence.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\embedding.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\force.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\force_matplotlib.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\image.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\monitoring.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\partial_dependence.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\summary.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\waterfall.py -> build\lib.win-amd64-3.9\shap\plots
    copying shap\plots\__init__.py -> build\lib.win-amd64-3.9\shap\plots
    creating build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\experiments.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\measures.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\methods.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\metrics.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\models.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\plots.py -> build\lib.win-amd64-3.9\shap\benchmark
    copying shap\benchmark\__init__.py -> build\lib.win-amd64-3.9\shap\benchmark
    creating build\lib.win-amd64-3.9\shap\plots\resources
    copying shap\plots\resources\bundle.js -> build\lib.win-amd64-3.9\shap\plots\resources
    copying shap\plots\resources\logoSmallGray.png -> build\lib.win-amd64-3.9\shap\plots\resources
    copying shap\tree_shap.h -> build\lib.win-amd64-3.9\shap
    running build_ext
    numpy.get_include() C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\python39\site-packages\numpy\core\include
    building 'shap._cext' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------

ERROR: Command errored out with exit status 1: 'C:\Users\Alex\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import sys,'"'"'exec'"'"'))' install --record 'C:\Users\Alex\AppData\Local\Temp\pip-record-bu1hm3ps\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\python39\Include\shap' Check the logs for full command output.

我也尝试先使用 conda install -c conda-forge shap 安装 shap,然后尝试安装 azureml-interpret 但我仍然遇到相同的问题

解决方法

我遇到了同样的问题,安装 C++ build 解决了这个问题。

见下文 How to install Visual C++ Build tools?