You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用model.push_to_hub上传模型至Hugging Face Hub遇NotADirectoryError求助

本地推送模型至Hugging Face Hub出现NotADirectoryError

问题详情

Hugging Face ID为aben118,上传模型名为test,执行代码:

peft_model_id = "aben118/test"
model.push_to_hub(peft_model_id)

触发错误:

NotADirectoryError: [Errno 20] Not a directory: '/u/hys4qm/.conda/envs/whisper/lib/python3.9/site-packages/huggingface_hub-0.20.3-py3.8.egg/huggingface_hub/templates/modelcard_template.md'

补充信息:Colab环境可成功推送,本地.py脚本运行失败;已执行pip3 install --upgrade huggingface_hub升级,但在/u/hys4qm/.conda/envs/whisper/lib/python3.9/site-packages/目录下未找到huggingface_hub-0.20.3-py3.8.egg文件夹。

解决步骤

  • 确认conda环境激活状态:执行conda activate whisper确保操作的是目标环境,防止pip安装到其他环境导致版本不匹配。
  • 彻底卸载并重装huggingface_hub:先执行pip uninstall huggingface_hub完全移除现有包,再重新安装pip install --upgrade huggingface_hub,避免egg格式包的残留问题。
  • 跳过模型卡片生成(临时修复):在push_to_hub调用中添加model_card=None参数,绕过模板文件读取逻辑,修改后代码:
peft_model_id = "aben118/test"
model.push_to_hub(peft_model_id, model_card=None)
  • 清理conda环境缓存:执行conda clean --all清除环境中不匹配的缓存文件,解决Python版本(报错路径显示py3.8,本地为py3.9)不一致导致的文件读取异常。

内容的提问来源于stack exchange,提问作者afsara_ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 21:53:17