我正在flair
使用带有www-data
用户(无sudo
权限)的包调用 python 脚本。模型位于该用户具有访问权限的路径中,我已设置flair.cache_root = Path("tools/flair")
但是,当我与该用户一起运行脚本时,出现权限错误:
tagger = MultiTagger.load([\\\"flair/ner-german-large\\\", \\\"de-pos\\\"])\
File \\\"/usr/local/lib/python3.7/dist-packages/flair/models/sequence_tagger_model.py\\\", line 1330, in load\
model = SequenceTagger.load(model_name)\
File \\\"/usr/local/lib/python3.7/dist-packages/flair/nn.py\\\", line 88, in load\
state = torch.load(f, map_location='cpu')\
File \\\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\\", line 594, in load\
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)\
File \\\"/usr/local/lib/python3.7/dist-packages/torch/serialization.py\\\", line 853, in _load\
result = unpickler.load()\
File \\\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\\", line 1297, in __setstate__\
state_dict=d[\\\"model_state_dict\\\"],\
File \\\"/usr/local/lib/python3.7/dist-packages/flair/embeddings/token.py\\\", line 818, in __init__\
self.tokenizer: PreTrainedTokenizer = AutoTokenizer.from_pretrained(model, **kwargs)\
File \\\"/usr/local/lib/python3.7/dist-packages/transformers/models/auto/tokenization_auto.py\\\", line 435, in from_pretrained\
return tokenizer_class_fast.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)\
File \\\"/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils_base.py\\\", line 1680, in from_pretrained\
user_agent=user_agent,\
File \\\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\\", line 1279, in cached_path\
local_files_only=local_files_only,\
File \\\"/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py\\\", line 1426, in get_from_cache\
os.makedirs(cache_dir, exist_ok=True)\
File \\\"/usr/lib/python3.7/os.py\\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\\"/usr/lib/python3.7/os.py\\\", line 211, in makedirs\
makedirs(head, exist_ok=exist_ok)\
File \\\"/usr/lib/python3.7/os.py\\\", line 221, in makedirs\
mkdir(name, mode)\
PermissionError: [Errno 13] Permission denied: '/root/.cache'\
我可以避免使用/root/.cache
吗?我不想编辑该目录的读写权限。如果我运行脚本,root
它工作正常。我如何以其他用户身份运行它?我在 Ubuntu 上运行它。