Permission denied: ‘/root/.huggingface/token‘

文章讲述了在使用HuggingFaceHub时遇到权限错误的问题,作者发现是由于当前目录权限不足导致。解决方案是通过设置Python环境变量`HUGGING_FACE_HUB_TOKEN`来指定一个新的可读写路径,从而避免对/root/.huggingface/token的访问权限问题。
摘要由CSDN通过智能技术生成

错误如下:

stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_headers.py", line 117, in build_hf_headers
    token_to_send = get_token_to_send(token)
  File "/home/oem/Project/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_headers.py", line 144, in get_token_to_send
    cached_token = HfFolder().get_token()
  File "/home/oem/Project/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_hf_folder.py", line 60, in get_token
    cls._copy_to_new_path_and_warn()
  File "/home/oem/Project/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/utils/_hf_folder.py", line 90, in _copy_to_new_path_and_warn
    if cls._old_path_token.exists() and not cls.path_token.exists():
  File "/home/oem/anaconda3/envs/stablediff/lib/python3.10/pathlib.py", line 1288, in exists
    self.stat()
  File "/home/oem/anaconda3/envs/stablediff/lib/python3.10/pathlib.py", line 1095, in stat
    return self._accessor.stat(self, follow_symlinks=follow_symlinks)
PermissionError: [Errno 13] Permission denied: '/root/.huggingface/token'

因为当前目录权限问题,所以打算修改环境变量,这个环境变量名称找了半天全网也没多少提到,直到看到了官方文档:
https://huggingface.co/docs/huggingface_hub/package_reference/environment_variables

官方文档

所以在Python代码中添加:

import os
os.environ['HUGGING_FACE_HUB_TOKEN'] = 'xxx' # 可以随意读写的路径即可,如
# os.environ['HUGGING_FACE_HUB_TOKEN'] = str(os.getcwd()) + '/transformers'

搞定!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值