huggingface_hub模型文件的问题

hf download 报 cannot locate the file on the Hub

报错原文

An error happened while trying to locate the file on the Hub and we cannot find the requested files in the local cache. Please check your connection and try again or make sure your Internet connection is on.

是什么意思

huggingface_hub 连不上 Hugging Face,本地缓存里也没有这个文件。仓库多半是存在的,是网络没连通 —— 在中国大陆直连时很常见。

为什么会出现

  • 这个网络访问不了 huggingface.co:被拦截、超时,或者需要代理而工具没有走代理。源码里,只要请求失败的原因不是仓库不存在、需要授权或 token 无效,就会走到这条报错。
  • 需要授权或私有的仓库会报另一种错误(401 或 gated repo),所以这条报错不是 token 的问题。

怎么解决

  1. 把下载地址换成镜像:在 hf download 之前执行 export HF_ENDPOINT=https://hf-mirror.com。HF_ENDPOINT 是 huggingface_hub 自带的 Hub 地址设置;hf-mirror.com 是第三方镜像,不是 Hugging Face 官方运营的。本站中文版的命令生成器已经自动加上了这一行。
  2. ollama pull hf.co/… 不读 HF_ENDPOINT。先经镜像用 hf download 下载 GGUF,再写一个 Modelfile(FROM ./文件名.gguf)用 ollama create 导入。

相关报错

核对来源

报错原文于 2026-10-28 从源码中读取核对。