pythonnumbashap

Importing SHAP occurs error even though updating all libraries


When I import shap, I get error as below.

I tried to reinstall shap and update conda, numpy, numba, llvmlite.

Interesting thing is that llvmlite version is 0.38.0 in jupyter notebook but the error occurs same as below.

Unexpected exception formatting exception. Falling back to standard exception

Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3369, in run_code
    ----------
  File "C:\Users\user\AppData\Local\Temp\ipykernel_22980\3975714860.py", line 1, in <cell line: 1>
    import shap
  File "C:\Users\user\anaconda3\lib\site-packages\shap\__init__.py", line 12, in <module>
    from ._explanation import Explanation, Cohorts
  File "C:\Users\user\anaconda3\lib\site-packages\shap\_explanation.py", line 12, in <module>
    from .utils._general import OpChain
  File "C:\Users\user\anaconda3\lib\site-packages\shap\utils\__init__.py", line 1, in <module>
    from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust
  File "C:\Users\user\anaconda3\lib\site-packages\shap\utils\_clustering.py", line 4, in <module>
    from numba import jit
  File "C:\Users\user\anaconda3\lib\site-packages\numba\__init__.py", line 199, in <module>
    _ensure_llvm()
  File "C:\Users\user\anaconda3\lib\site-packages\numba\__init__.py", line 111, in _ensure_llvm
    raise ImportError(msg)
ImportError: Numba requires at least version 0.38.0 of llvmlite.
Installed version is 0.37.0.
Please update llvmlite.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 1982, in showtraceback
    'the full traceback.\n']
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1118, in structured_traceback
    return FormattedTB.structured_traceback(
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1012, in structured_traceback
    return VerboseTB.structured_traceback(
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 865, in structured_traceback
    formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 818, in format_exception_as_a_whole
    frames.append(self.format_record(r))
  File "C:\Users\user\anaconda3\lib\site-packages\IPython\core\ultratb.py", line 736, in format_record
    result += ''.join(_format_traceback_lines(frame_info.lines, Colors, self.has_colors, lvals))
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\core.py", line 698, in lines
    pieces = self.included_pieces
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\core.py", line 649, in included_pieces
    pos = scope_pieces.index(self.executing_piece)
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\utils.py", line 145, in cached_property_wrapper
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "C:\Users\user\anaconda3\lib\site-packages\stack_data\core.py", line 628, in executing_piece
    return only(
  File "C:\Users\user\anaconda3\lib\site-packages\executing\executing.py", line 164, in only
    raise NotOneValueFound('Expected one value, found 0')
executing.executing.NotOneValueFound: Expected one value, found 0

After I tried to update with "conda update llvmlite".

I got an error as below. What should I have to do?

(base) C:\Users\user>conda update llvmlite
Collecting package metadata (current_repodata.json): failed

CondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to
download and install packages.

Exception: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/win-64/current_repodata.json (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

Solution

  • There is a conflict between numba and llvm version while importing.

    Read the below lines carefully:

    ImportError: Numba requires at least version 0.38.0 of llvmlite.
    Installed version is 0.37.0.
    Please update llvmlite.
    

    Try:

    conda list llvmlite
    

    or, if needed

    conda update llvmlite
    

    As you claim you already have the correct llvmlite in path, I think the shortest path is to do

    conda deactivate
    pip install -U llvmlite
    

    Otherwise, search for problems in your $PATH / env defintions