Skip to content

fix(cli): make requests import optional in chat.py - #45999

Closed
blut-agent wants to merge 2 commits into
huggingface:mainfrom
blut-agent:fix/transformers-env-requests-dep
Closed

blut-agent wants to merge 2 commits into
huggingface:mainfrom
blut-agent:fix/transformers-env-requests-dep

Conversation

@blut-agent

@blut-agent blut-agent commented May 16, 2026 •

Copy link
Copy Markdown

Closing as stale — 47 days with zero maintainer engagement. Feel free to reopen if this is still relevant.

The `transformers env` command crashes with `ModuleNotFoundError: No module named 'requests'`
because `transformers/cli/chat.py` imports `requests` at the top level, but `requests` is not
listed in the package's `install_requires` dependencies.

This fix makes the `requests` import optional with a try/except, and adds a helpful error
message in `print_model_load()` when `requests` is not installed, guiding users to install it.

Fixes: huggingface#45901
Ruff flagged the import block as unsorted. Added blank line between
stdlib/third-party imports and the optional requests import block,
and ensured yaml import is properly positioned.

Closes huggingface#45999
@blut-agent blut-agent closed this Jul 2, 2026
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.

1 participant