Skip to content

[CLI] Fix installation method detection for curl-installed hf with Homebrew Python#4142

Merged
Wauplin merged 2 commits into
mainfrom
cursor/fix-installation-method-detection-d2f2
Apr 27, 2026
Merged

[CLI] Fix installation method detection for curl-installed hf with Homebrew Python#4142
Wauplin merged 2 commits into
mainfrom
cursor/fix-installation-method-detection-d2f2

Conversation

@Wauplin

@Wauplin Wauplin commented Apr 24, 2026

Copy link
Copy Markdown
Collaborator

Context: https://huggingface.slack.com/archives/C07KX53FZTK/p1777043578920709

Summary

Fixes hf env reporting Installation method: brew when hf was actually installed via the curl installer (curl -LsSf https://hf.co/cli/install.sh | bash) on a system where Python comes from Homebrew.

Root cause: _is_brew_installation() was checked before _is_hf_installer_installation() in installation_method(). The brew check used sys.executable resolved through symlinks, which points back to Homebrew's Python (e.g. /opt/homebrew/Cellar/python@3.12/...) even when running inside the curl installer's venv. Since the old check matched on /opt/homebrew/ prefix, it would always win.

Fix:

  • Reorder checks: _is_hf_installer_installation() (uses a definitive marker file) is now checked before the brew heuristic
  • Tighten brew detection: check sys.prefix (the venv/prefix root) for /Cellar/hf/ instead of checking sys.executable for /opt/homebrew/. The brew formula's libexec venv lives at e.g. /opt/homebrew/Cellar/hf/0.30.0/libexec/, so this is specific to actual brew installs

Scenarios:

Install method sys.prefix sys.executable (resolved) Old result New result
brew install hf /opt/homebrew/Cellar/hf/0.30/libexec /opt/homebrew/Cellar/python@3.12/.../python3.12 brew brew
curl installer + Homebrew Python ~/.local/share/hf/venv /opt/homebrew/Cellar/python@3.12/.../python3.12 brew (wrong) hf_installer
pip install + Homebrew Python /opt/homebrew/opt/python@3.12/... /opt/homebrew/Cellar/python@3.12/.../python3.12 brew pip

Slack Thread

Open in Web Open in Cursor 

…mebrew Python

The _is_brew_installation() check was matching before _is_hf_installer_installation()
when the user's system Python came from Homebrew. This caused 'hf env' to report
'Installation method: brew' even when hf was installed via the curl installer.

Two fixes:
1. Reorder checks: hf_installer (marker file) is checked before brew (heuristic)
2. Tighten brew detection: check sys.prefix for '/Cellar/hf/' (the formula's
   libexec venv) instead of sys.executable for '/opt/homebrew/' (which matches
   any Homebrew-installed Python)

Co-authored-by: Lucain <Wauplin@users.noreply.github.com>
@julien-c

Copy link
Copy Markdown
Member

agree with this approach, should work!

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@Wauplin Wauplin marked this pull request as ready for review April 27, 2026 13:13
@Wauplin Wauplin requested a review from hanouticelina April 27, 2026 13:13

@hanouticelina hanouticelina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Wauplin Wauplin merged commit 30b368c into main Apr 27, 2026
17 of 21 checks passed
@Wauplin Wauplin deleted the cursor/fix-installation-method-detection-d2f2 branch April 27, 2026 14:03
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.13.0 release.

@julien-c

Copy link
Copy Markdown
Member

i can confirm this is now solved:

$ hf env

Copy-and-paste the text below in your GitHub issue.

- huggingface_hub version: 1.13.0
- Platform: macOS-26.4.1-arm64-arm-64bit-Mach-O
- Python version: 3.14.4
[...]
- Token path ?: /Users/gibbon/.cache/huggingface/token
- Has saved token ?: True
- Who am I ?: julien-c
- Configured git credential helpers: osxkeychain
- Run by AI agent ?: No
- Installation method: hf_installer
[...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants