Numba needs NumPy 1.20 or less for shapley import
Asked Answered
D

7

26

I am trying to import shap. I am getting the following bug. I installed the lower version of NumPy still the problem is not solved. Thank you!

 import shap


ImportError                               Traceback (most recent call last)
/tmp/ipykernel_22681/948769371.py in <module>
----> 1 import shap

~/jupyter/environment/lib/python3.8/site-packages/shap/__init__.py in <module>
     10     warnings.warn("As of version 0.29.0 shap only supports Python 3 (not 2)!")
     11 
---> 12 from ._explanation import Explanation, Cohorts
     13 
     14 # explainers

~/jupyter/environment/lib/python3.8/site-packages/shap/_explanation.py in <module>
     10 from slicer import Slicer, Alias, Obj
     11 # from ._order import Order
---> 12 from .utils._general import OpChain
     13 
     14 # slicer confuses pylint...

~/jupyter/environment/lib/python3.8/site-packages/shap/utils/__init__.py in <module>
----> 1 from ._clustering import hclust_ordering, partition_tree, partition_tree_shuffle, delta_minimization_order, hclust
      2 from ._general import approximate_interactions, potential_interactions, sample, safe_isinstance, assert_import, record_import_error
      3 from ._general import shapley_coefficients, convert_name, format_value, ordinal_str, OpChain
      4 from ._show_progress import show_progress
      5 from ._masked_model import MaskedModel, make_masks

~/jupyter/environment/lib/python3.8/site-packages/shap/utils/_clustering.py in <module>
      2 import scipy as sp
      3 from scipy.spatial.distance import pdist
----> 4 from numba import jit
      5 import sklearn
      6 import warnings

~/jupyter/environment/lib/python3.8/site-packages/numba/__init__.py in <module>
    196 
    197 _ensure_llvm()
--> 198 _ensure_critical_deps()
    199 
    200 # we know llvmlite is working as the above tests passed, import it now as SVML

~/jupyter/environment/lib/python3.8/site-packages/numba/__init__.py in _ensure_critical_deps()
    136         raise ImportError("Numba needs NumPy 1.17 or greater")
    137     elif numpy_version > (1, 20):
--> 138         raise ImportError("Numba needs NumPy 1.20 or less")
    139 
    140     try:

ImportError: Numba needs NumPy 1.20 or less
Diplegia answered 28/11, 2021 at 22:37 Comment(1)
I got this working by changing my Python environment from Conda (Anaconda) to the regular Python binary. Then, the Numpy and Numa version issues were resolved.Tern
C
26

I believe the numba's dependency with numpy 1.22 have been resolved in the most recent version. Try upgrading numba (works for me with numpy 1.22):

pip install numba --upgrade
Cosmetic answered 3/6, 2022 at 21:20 Comment(0)
C
21

I use Numpy==1.21.4 and Numba==0.53.0, it works:

pip install numba==0.53
Condorcet answered 7/12, 2021 at 3:29 Comment(1)
pip install numpy==1.24.4 pip install numba==0.57.1 , also compatibleBookcase
I
6

I had same issue, these steps has worked for me.
1.

pip3 install numpy==1.21.4
pip3 install pip install numba==0.53.0
pip3 install librosa
or 
sudo apt install librosa

For more understanding please visit Click here
I hope this helps you.

Indeed answered 4/8, 2022 at 11:8 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Caddish
R
4

I used pip install shap instead of conda install -c conda-forge shap and it worked for me.

Rig answered 18/4, 2022 at 16:16 Comment(1)
This is what worked for me in sagemaker studio. It uninstalled the incompatible numpy version, and installed the compatible one. For some reason, conda wasn't doing it, causing inconsistencies.Pratincole
S
1

I ran into the same issue. the solution is to install numpy 1.18.1 with numpa 0.48.0 and it should work

Slattern answered 30/11, 2021 at 18:26 Comment(0)
O
1

I had the same issue. You have to restart the Jupyter kernel after downgrading Numpy.

You can downgrade using:

pip install numpy==[version]

Here,

pip install numpy==1.20

Olnton answered 29/6, 2023 at 23:6 Comment(0)
W
0

as of today I am able to run numba==0.57.1 with numpy==1.21.4

Womb answered 27/3 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.