How to Install transformers in Python
Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
pip install transformers
What is transformers?
Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.
English | 简体中文 | 繁體中文 | 한국어 | Español | 日本語 | हिन्दी | Русский | Português | తెలుగు | Français | Deutsch | Italiano | Tiếng Việt | العربية | اردو | বাংলা |
State-of-the-art pretrained models for inference and training
Transformers acts as the model-definition framework for state-of-the-art machine learning with text, computer vision, audio, video, and multimodal models, for both inference and training.
Quick Start
Minimal example to get started with transformers:
from transformers import pipeline
# Sentiment analysis
classifier = pipeline("sentiment-analysis")
result = classifier("I love this library!")
print(result) # [{'label': 'POSITIVE', 'score': 0.9998}]
Installation
pip (standard)
pip install transformers
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install transformers
pip3
pip3 install transformers
conda
conda install -c conda-forge transformers
Poetry
poetry add transformers
Dependencies
Installing transformers will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import transformers; print(transformers.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing transformers with pip.
ModuleNotFoundError: No module named 'transformers'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install transformers. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'transformers' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install transformers to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'transformers'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show transformers and upgrade with pip install --upgrade transformers.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install transformers. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user transformers
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org transformers
RuntimeError: CUDA out of memory
Cause: Model or batch size exceeds GPU memory.
Fix: Reduce batch size, call torch.cuda.empty_cache(), or run on CPU.
Recent Releases
| Version | Released |
|---|---|
5.5.1 |
2026-04-09 |
5.5.2 |
2026-04-09 |
5.5.3 latest |
2026-04-09 |
5.5.0 |
2026-04-02 |
5.4.0 |
2026-03-27 |
Manage transformers
Upgrade to latest version
pip install --upgrade transformers
Install a specific version
pip install transformers==5.5.3
Uninstall
pip uninstall transformers
Check what is installed
pip show transformers