huggingface 下载方法 测试ok
目录
设置环境变量
python 下载无token:
python 下载加token
常见报错
设置环境变量
Linux
export HF_ENDPOINT=https://hf-mirror.com
- Windows Powershell
$env:HF_ENDPOINT = "https://hf-mirror.com"
pip install -U huggingface_hub
huggingface-cli download --h
$env:HF_ENDPOINT = "https://hf-mirror.com"
huggingface-cli download --resume-download gpt2--local-dir gpt2
python 下载无token:
报错,和浏览器的一样,401错误
# 设置环境变量
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
# 代码下载
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev" ,filename="model_index.json" ,local_dir="./qafacteval")
python 下载加token
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
from huggingface_hub import snapshot_download
local_dir = r"B:\data\aigc1"
repo_id = "black-forest-labs/FLUX.1-dev"
token = "xxxxxx"
snapshot_download(repo_id=repo_id, local_dir=local_dir, resume_download=True, local_dir_use_symlinks=False, token=token)
# 没成功:
# from huggingface_hub import hf_hub_download
# hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev" ,filename="model_index.json" ,local_dir="./qafacteval")
常见报错
- huggingface-cli: error: invalid choice: ‘download’ (choose from ‘env’, ‘login’, ‘whoami’, ‘logout’, ‘repo’, ‘lfs-enable-largefiles’, ‘lfs-multipart-upload’, ‘scan-cache’, ‘delete-cache’)
- 可能是由于python版本<3.8,下载的huggingface-cli版本过低;在python>=3.8环境下运行
pip install -U huggingface_hub
命令后解决
- 可能是由于python版本<3.8,下载的huggingface-cli版本过低;在python>=3.8环境下运行
- ModuleNotFoundError: No module named ‘chardet’
- 安装对应模块即可:
pip install chardet
- 安装对应模块即可: