Skip to main content

How to Install Hugging Face Transformers with uv

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

Hugging Face Transformers is the Python library that downloads pretrained models from the Hugging Face Hub and runs them, and it uses PyTorch to do the maths. This guide installs both into a uv project, then checks that everything is in place, with Transformers 5.24.1 and PyTorch 2.15.0 on Python 3.14.

Syntax​

Syntax
uv add transformers torch
PartWhat it means
uv addAdds packages to the project in the current folder, and records them in pyproject.toml and uv.lock
transformersThe Hugging Face library itself
torchPyTorch, the deep-learning framework Transformers runs models with. Transformers 5 works with PyTorch only

The Transformers installation guide says: "Transformers works with PyTorch. It has been tested on Python 3.11+ and PyTorch 2.6+."

The Example​

A new project, hello-transformers, gets Transformers and PyTorch, then reports the versions it got.

Prerequisites​

  • uv. This guide uses uv 0.13.10. It downloads Python 3.14 for you if your computer doesn't have it.
  • About 1 GB of free disk space for PyTorch and the other packages.

Step 1: Create the Project on Python 3.14​

Terminal
uv init --python 3.14 hello-transformers
cd hello-transformers
Output
Initialized project `hello-transformers` at `/Users/you/source/hello-transformers`

Why 3.14 and not the newer 3.15? Transformers 5.24.1 lists Python 3.11 to 3.14 as its supported versions, so 3.14 is the newest one it supports.

Step 2: Add Transformers and PyTorch​

Terminal
uv add transformers torch
Output
Using CPython 3.14.10
Creating virtual environment at: .venv
Resolved 60 packages in 1.94s
Built hello-transformers @ file:///Users/you/source/hello-transformers
Prepared 2 packages in 2.37s
Installed 39 packages in 627ms
+ annotated-doc==0.0.7
+ annotated-types==0.8.0
+ anyio==4.16.0
+ click==8.5.1
+ filelock==4.3.2
+ fsspec==2026.9.0
+ h11==0.16.0
+ hello-transformers==0.1.0 (from file:///Users/you/source/hello-transformers)
+ hf-xet==1.8.0
+ httpcore2==2.17.0
+ httpx2==2.17.0
+ huggingface-hub==2.5.0
+ idna==3.20
+ jinja2==3.1.6
+ markdown-it-py==4.3.0
+ markupsafe==3.0.4
+ mdurl==0.1.2
+ mpmath==1.3.0
+ networkx==3.7
+ numpy==2.5.5
+ packaging==26.4
+ pydantic==2.14.4
+ pydantic-core==2.50.5
+ pygments==2.21.0
+ pyyaml==6.0.4
+ regex==2026.11.30
+ rich==15.0.0
+ safetensors==0.8.0
+ setuptools==84.2.1
+ shellingham==1.5.4
+ sympy==1.14.0
+ tokenizers==0.23.3
+ torch==2.15.0
+ tqdm==4.70.1
+ transformers==5.24.1
+ truststore==0.10.5
+ typer==0.29.3
+ typing-extensions==4.16.0
+ typing-inspection==0.4.5

The terminal after uv add transformers torch: uv used CPython 3.14.10, created .venv, resolved 60 packages and installed 39 of them, including huggingface-hub 2.5.0, safetensors 0.8.0, tokenizers 0.23.3, torch 2.15.0 and transformers 5.24.1.

uv created the project's virtual environment, .venv, and installed Transformers with everything it needs. Three of those packages do important work behind the scenes:

PackageWhat it does
huggingface-hubDownloads models from the Hub and keeps them in a local cache
tokenizersSplits text into the pieces a model reads, fast
safetensorsLoads model weights from .safetensors files, a safe format that can't run code

Windows with an NVIDIA GPU​

uv add torch installs PyTorch from PyPI, and uv's PyTorch guide explains that PyPI "hosts CPU-only wheels for Windows and macOS, and GPU-accelerated wheels on Linux". On a Mac, that build still uses Apple's GPU through MPS. On Windows, it runs on the CPU only: to use an NVIDIA GPU there, install a CUDA build from PyTorch's own index as that guide shows.

Step 3: Check the Version​

Terminal
uv run python -c "import transformers; print(transformers.__version__)"
Output
5.24.1

The terminal after the version check: 5.24.1.

Step 4: Read the Environment Report​

Transformers comes with a transformers command. transformers env prints the versions that matter when something goes wrong:

Terminal
uv run transformers env
Output
Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

- `transformers` version: 5.24.1
- Platform: macOS-26.7.4-arm64-arm-64bit-Mach-O
- Python version: 3.14.10
- Huggingface_hub version: 2.5.0
- Safetensors version: 0.8.0
- Accelerate version: not installed
- Accelerate config: not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.15.0 (NA)
- Using distributed or parallel set-up in script?: <fill in>

The terminal after uv run transformers env: transformers 5.24.1, macOS on arm64, Python 3.14.10, huggingface_hub 2.5.0, safetensors 0.8.0, Accelerate and DeepSpeed not installed, and PyTorch 2.15.0 with the accelerator shown as NA.

The report is meant to be pasted into bug reports, which is why it starts with "Copy-and-paste the text below in your GitHub issue".

On a Mac, (NA) after the PyTorch version doesn't mean PyTorch can't use the GPU. The command looks for CUDA, XPU, NPU, HPU and SUPA accelerators, but not for Apple's MPS, so it prints NA even when torch.backends.mps.is_available() is True, as it is on this M1 Pro. I reported it to Transformers as issue #51548. The commands in this guide work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Installing only transformersModels can't run: Transformers needs PyTorch to do the workAdd both: uv add transformers torch
Creating the project on a Python that Transformers doesn't list yetParts of the Hugging Face stack can fail. On Python 3.15, the datasets library's map with several processes fails, as Fixed: AttributeError: 'code' object has no attribute 'co_lnotab' showsUse --python 3.14
Running python -c "import transformers" outside the projectModuleNotFoundError: No module named 'transformers', unless your system Python has its own copy: the packages are in the project's .venvRun it through uv run from the project folder

FAQ​

Does this download any models?​

No. Installing only adds the libraries. Models are downloaded the first time you load one, and stay in the Hugging Face cache.

Can I use pip instead of uv?​

Yes. The installation guide shows pip commands too. uv adds a project, a lock file and a pinned Python version, which keeps installs repeatable.

Conclusion​

uv add transformers torch installed Transformers 5.24.1 and PyTorch 2.15.0 into a Python 3.14 project. The version check printed 5.24.1, and transformers env listed the rest, apart from the Mac GPU, which it doesn't detect.

Additional Resources​