Installing and Importing Transformers
What You'll Learn
You'll learn how to set up the transformers library on your system and verify it's ready to use.
Why This Matters
Now that you know how to find models on the Hugging Face Hub, you need the actual software to run them. The transformers library is your bridge between browsing models online and using them in your code. Think of it like installing a video game before you can play it—the Hub shows you what's available, but the library lets you actually run the models.
Installing the Library
The transformers library is installed via Python's package manager. Open your terminal and run:
pip install transformers
This command downloads the library and its core dependencies. The process usually takes 1-2 minutes depending on your internet speed.
What gets installed? The library includes code for loading models, tokenizers (text processors), and utilities for running predictions. Dependencies like PyTorch or TensorFlow may install automatically if you don't have them yet.
Verifying Your Installation
After installation, test that everything works by opening a Python shell or notebook and typing:
import transformers
print(transformers.__version__)
If you see a version number (like 4.35.0), you're ready to go! No error means the library is properly installed and Python can find it.
Common Dependencies
The transformers library works alongside deep learning frameworks. You'll typically need either PyTorch or TensorFlow installed, though basic imports work without them. Don't worry about installing these separately right now—transformers handles basic needs automatically.
Key Takeaway: Installing transformers with pip install transformers and verifying with import transformers confirms your environment is ready to load and use models from the Hugging Face Hub.