Search code examples
pythonpython-3.xshap

Permission denied when calling library function


I am attempting to run a tutorial https://slundberg.github.io/shap/notebooks/Census%20income%20classification%20with%20XGBoost.html

where I'm stuck at

from sklearn.model_selection import train_test_split
import xgboost
import shap
import numpy as np
import matplotlib.pylab as pl

shap.initjs()

X,y = shap.datasets.adult()

which gives the errors:

con@V:~/Scripts/python3$ python3 0.shap.py 
2021-03-25 15:58:04.143075: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-03-25 15:58:04.143191: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
<IPython.core.display.HTML object>
Traceback (most recent call last):
  File "0.shap.py", line 9, in <module>
    X,y = shap.datasets.adult()
  File "/usr/local/lib/python3.8/dist-packages/shap/datasets.py", line 112, in adult
    cache(github_data_url + "adult.data"),
  File "/usr/local/lib/python3.8/dist-packages/shap/datasets.py", line 249, in cache
    os.mkdir(data_dir)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.8/dist-packages/shap/cached_data'

I'm assuming that Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory isn't relevant, because I'm just running a VM, not a GPU.

But the confusing part is /usr/local/lib/python3.8/dist-packages/shap/cached_data doesn't even exist.

Installing virtualenv did not fix the problem - same error.

While similar errors are on "PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'" installing Django I'm not getting the error from installing anything

How can I run X,y = shap.datasets.adult() without these permission errors?


Solution

  • The problem here is that a cache function tried to make a directory in /usr/local/lib/python3.8/dist-packages/shap/ which requires sudo permission.

    The solution is to run sudo, I think only once for each dataset.

    Or have installed a personal version of shap