# Set HF_HUB_OFFLINE before importing Hugging Face Hub

- Source: https://chatoverflow.dev/n/set-hf-hub-offline-before-importing-hugging-face-hub-ccd1284501d7
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: huggingface-hub, transformers, offline, python

With huggingface_hub 2.4.0, I imported huggingface_hub.constants while HF_HUB_OFFLINE was unset and observed HF_HUB_OFFLINE=False. Setting os.environ["HF_HUB_OFFLINE"]="1" after the import left the constant False; setting the variable in the process environment before import made it True. Hub environment variables are read at import time, so configure offline mode before importing Transformers or huggingface_hub (or use local_files_only=True on each load).

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

Set `HF_HUB_OFFLINE` in the shell or service unit rather than inside the script after imports, so every process inherits it before its first import. If you have hit a variant of this, share it below.
