PyTorch
TensorFlow 2.0
machine learning models
tokenizers
data utilities

Neither PyTorch nor TensorFlow 2.0 have been found.Models won't be available and only tokenizers, configuration and file/data utilities can be used

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

This warning usually appears when the Hugging Face transformers package is installed, but no supported deep learning backend is available in the current Python environment. It looks alarming, but it does not mean the package is broken. It means you can still use lightweight features such as tokenizers and configuration loading, while actual model classes stay unavailable until you install PyTorch or TensorFlow.

What the Warning Actually Means

transformers is split into two layers:

  • backend-independent utilities such as tokenizers, config objects, and file downloads
  • backend-dependent model classes that need PyTorch or TensorFlow to build tensors and run forward passes

So this warning:

Neither PyTorch nor TensorFlow 2.0 have been found

is really saying, "the package imports, but model execution is disabled."

That is why code like this still works:

python
1from transformers import AutoTokenizer
2
3tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
4encoded = tokenizer("Transformers can tokenize without a model.")
5
6print(encoded["input_ids"][:8])

The tokenizer can download files, read vocabulary assets, and convert text into token IDs without needing a tensor library.

What Will Not Work

Model loading requires a backend. If you try this without PyTorch or TensorFlow installed, you will get an import error or backend warning:

python
from transformers import AutoModel

model = AutoModel.from_pretrained("distilbert-base-uncased")

The reason is simple: AutoModel needs tensors, parameter storage, and runtime kernels. Token IDs alone are not enough.

The Usual Fix

Install one supported backend in the same environment where transformers is installed. PyTorch is the most common choice for examples and research workflows:

bash
pip install transformers torch

If your project uses TensorFlow instead:

bash
pip install transformers tensorflow

Then verify the environment:

python
1import transformers
2
3try:
4    import torch
5    print("PyTorch:", torch.__version__)
6except ImportError:
7    print("PyTorch not installed")
8
9try:
10    import tensorflow as tf
11    print("TensorFlow:", tf.__version__)
12except ImportError:
13    print("TensorFlow not installed")
14
15print("Transformers:", transformers.__version__)

Once one backend is available, the model APIs become usable:

python
1from transformers import AutoTokenizer, AutoModel
2
3tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
4model = AutoModel.from_pretrained("distilbert-base-uncased")
5
6inputs = tokenizer("Now the model can run.", return_tensors="pt")
7outputs = model(**inputs)
8
9print(outputs.last_hidden_state.shape)

That example assumes PyTorch is installed because return_tensors="pt" asks for PyTorch tensors.

How Environment Mismatches Cause This

In practice, the warning often appears because the user installed packages into different environments. Common cases include:

  • 'transformers installed in one virtual environment and torch in another'
  • Anaconda or venv environment activated incorrectly
  • Jupyter notebook kernel pointing at a different interpreter from the terminal
  • IDE using a different Python binary than the shell

A quick sanity check is:

bash
1python -m pip show transformers
2python -m pip show torch
3python -m pip show tensorflow
4python -c "import sys; print(sys.executable)"

Using python -m pip instead of plain pip avoids many path mistakes.

When Tokenizer-Only Usage Is Fine

Sometimes the warning is acceptable. If your code only needs:

  • vocabulary inspection
  • preprocessing text into IDs
  • downloading configs
  • reading model metadata

then you may not need a backend at all. That can be useful in preprocessing jobs or build steps where inference is not required.

The key point is that transformers is not all-or-nothing. It can still be useful in a restricted mode.

Common Pitfalls

The biggest mistake is installing both PyTorch and TensorFlow just to silence the warning. You only need the backend your project actually uses.

Another mistake is assuming the warning refers to a broken model file. It is usually an environment issue, not a corrupted download.

A third problem is copying example code with return_tensors="pt" while only TensorFlow is installed, or using return_tensors="tf" while only PyTorch is installed. The tensor type must match the backend.

Summary

  • The warning means transformers is installed but no supported model backend is available.
  • Tokenizers, configs, and file utilities still work without PyTorch or TensorFlow.
  • Model classes such as AutoModel require a backend to be installed in the same environment.
  • 'python -m pip is the safest way to verify and install packages in the correct interpreter.'
  • You only need one backend unless the project explicitly depends on both.

Course illustration
Course illustration

All Rights Reserved.