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
- 对比路径差异:在Jupyter单元格执行
!echo $PATH,终端执行echo $PATH,找出终端有但Jupyter缺失的路径。 - 修改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"}
- 执行
- 若使用conda环境,确保Jupyter kernel基于该环境创建:执行
conda activate your-env && python -m ipykernel install --user --name your-env,这样Jupyter会自动继承环境的PATH。
- 对比路径差异:在Jupyter单元格执行
内容的提问来源于stack exchange,提问作者Raptor
相关产品推荐
相关产品推荐

