setup with Python virtual environment
You can verify the installation by running:
>>> import transformers
I would like to list some common issues:
>>> import transformers
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'transformers'
It looks like your installation was not successful or you didn't activate the virtual environment.
>>> from transformers import pipeline
...
... classifier = pipeline("sentiment-analysis")
... classifier("I've been waiting for a HuggingFace course my whole life.")
...
[transformers] PyTorch was not found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
[transformers] PyTorch was not found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
[transformers] No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision 714eb0f.
Using a pipeline without specifying a model name and revision in production is not recommended.
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
config.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 629/629 [00:00<00:00, 2.73MB/s]
Traceback (most recent call last):
File "<python-input-0>", line 3, in <module>
classifier = pipeline("sentiment-analysis")
File "/home/mc/.venv-transformers/lib/python3.13/site-packages/transformers/pipelines/__init__.py", line 1024, in pipeline
if isinstance(dtype, str) and hasattr(torch, dtype):
^^^^^
NameError: name 'torch' is not defined
To fix the issue install Pytorch.
untimeError: At least one of TensorFlow 2.0 or PyTorch should be installed. To install TensorFlow 2.0, read the instructions at https://www.tensorflow.org/install/ To install PyTorch, read the instructions at https://pytorch.org/.
To fix the issue install tensorflow with pip install tensorflow==2.14.0 as well.
Could not find cuda drivers on your machine, GPU will not be used.
This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
TF-TRT Warning: Could not find TensorRT