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

JupyterHub执行trainer.push_to_hub()报错:huggingface-cli不在$PATH中

解决HuggingFace Hub推送时huggingface-cli不在PATH的问题
  • 定位huggingface-cli的实际路径
    在Jupyter单元格执行!which huggingface-cli,若返回空,就在终端执行which huggingface-cli,记下输出的绝对路径(比如/home/your-user/.local/bin/huggingface-cli)。

  • 临时修复:在代码中补全环境变量
    调用push_to_hub()前,通过Python代码把huggingface-cli所在目录加入PATH:

    import os
    # 替换为你找到的路径
    huggingface_cli_dir = "/home/your-user/.local/bin"
    os.environ["PATH"] += os.pathsep + huggingface_cli_dir
    

    或者直接在推送时指定命令的绝对路径:

    trainer.push_to_hub(hub_command="/home/your-user/.local/bin/huggingface-cli")
    
  • 永久修复:统一Jupyter与终端的PATH

    1. 对比路径差异:在Jupyter单元格执行!echo $PATH,终端执行echo $PATH,找出终端有但Jupyter缺失的路径。
    2. 修改Jupyter配置:
      • 执行!jupyter notebook --generate-config生成配置文件(未生成过的话)。
      • 打开配置文件(通常在~/.jupyter/jupyter_notebook_config.py),找到c.Spawner.env_keep,确保它包含"PATH",或者直接添加缺失路径:
        c.Spawner.env = {"PATH": "/home/your-user/.local/bin:$PATH"}
        
    3. 若使用conda环境,确保Jupyter kernel基于该环境创建:执行conda activate your-env && python -m ipykernel install --user --name your-env,这样Jupyter会自动继承环境的PATH。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 06:37:03