使用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
相关产品推荐
相关产品推荐

