调用库函数时权限被拒绝

Permission denied when calling library function

我正在尝试 运行 教程 https://slundberg.github.io/shap/notebooks/Census%20income%20classification%20with%20XGBoost.html

我被困在什么地方

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()

给出错误:

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'

我假设 Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory 不相关,因为我只是 运行 安装虚拟机,而不是 GPU。

但令人困惑的是 /usr/local/lib/python3.8/dist-packages/shap/cached_data 根本不存在。

安装 virtualenv 没有解决问题 - 同样的错误。

虽然出现了类似的错误 我安装任何东西都没有收到错误

我怎样才能 运行 X,y = shap.datasets.adult() 没有这些权限错误?

这里的问题是 cache 函数试图在 /usr/local/lib/python3.8/dist-packages/shap/ 中创建目录,这需要 sudo 权限。

解决方案是运行sudo,我想每个数据集只做一次。

或者安装了个人版shap