Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[CLI] Don't let hf update self-upgrade a pip install on Windows
Windows refuses to replace the `hf.exe` launcher of a running process,
so `pip install -U huggingface_hub` spawned by `hf update` fails with
WinError 32 after having uninstalled the current version, leaving a dead
launcher and no `huggingface_hub` module. Print the command for the user
to run instead, like pip does for its own self-upgrade.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
  • Loading branch information
Wauplin and claude committed Sep 7, 2026
commit 8079f66eb4f6235e74ffacd67162c0c50ac43e6c
12 changes: 12 additions & 0 deletions src/huggingface_hub/cli/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import click

from huggingface_hub import __version__, constants
from huggingface_hub.errors import CLIError

from ..utils import dump_environment_info, installation_method
from ._cli_utils import _fetch_latest_pypi_version, run_update
Expand All @@ -46,6 +47,17 @@ def update() -> None:
out.text(f"hf is up to date ({__version__})")
return

# Windows refuses to replace the `hf.exe` launcher of a running process: pip would fail with a
# "file in use" error (WinError 32) *after* having uninstalled the current version, leaving a dead
# `hf.exe` and no `huggingface_hub` module behind. Print the command instead of running it, the same
# way pip refuses to upgrade itself on Windows.
if sys.platform == "win32" and installation_method() == "pip":
command = subprocess.list2cmdline([sys.executable, "-m", "pip", "install", "-U", "huggingface_hub"])
raise CLIError(
"On Windows, a pip-installed `hf` cannot update itself: pip is not allowed to replace `hf.exe` while it "
f"is running. Run this command instead:\n {command}"
)

# The standalone installer installs the `hf-cli` skill by default. If it's not installed at this
# point, the user opted out (or removed it): tell the installer to leave it alone instead of
# silently undoing that choice.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5009,6 +5009,8 @@ def _mocked_update(self) -> Generator[Mock, None, None]:
with (
patch("huggingface_hub.cli.system._fetch_latest_pypi_version", return_value="99.0.0"),
patch("huggingface_hub.cli.system.subprocess.call", return_value=0),
# `hf update` refuses to self-update a pip install on Windows: pretend we're not on Windows.
patch("huggingface_hub.cli.system.sys.platform", "linux"),
patch("huggingface_hub.cli.system.run_update", return_value=0) as mock_run_update,
):
yield mock_run_update
Expand Down
Loading