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:
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:
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:
If your project uses TensorFlow instead:
Then verify the environment:
Once one backend is available, the model APIs become usable:
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:
- '
transformersinstalled in one virtual environment andtorchin another' - Anaconda or
venvenvironment 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:
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
transformersis installed but no supported model backend is available. - Tokenizers, configs, and file utilities still work without PyTorch or TensorFlow.
- Model classes such as
AutoModelrequire a backend to be installed in the same environment. - '
python -m pipis the safest way to verify and install packages in the correct interpreter.' - You only need one backend unless the project explicitly depends on both.

