ModuleNotFoundError: No module named 'tokenizers'
Fixes ModuleNotFoundError: No module named 'tokenizers' Use when transformers raises `No module named 'tokenizers'` or 'requires the Tokenizers library but it was not found' Not for: `No module named 'transformers'` (install transformers itself first)
How to fix ModuleNotFoundError: No module named 'tokenizers'
Install the missing Rust tokenizer backend: python -m pip install tokenizers. transformers needs it for every *Fast tokenizer (BertTokenizerFast etc.). Make sure you install into the same environment that runs the code: python -m pip with the python you actually use.
The exact error
ModuleNotFoundError: No module named 'tokenizers'Fix it
python -m pip install tokenizers
Expected: Successfully installed tokenizers
python -c "import tokenizers; print(tokenizers.__version__)"
Expected: prints a version
- Retry your transformers import.
Expected: works
When this applies
transformers raises No module named 'tokenizers' or 'requires the Tokenizers library but it was not found'
When this does NOT apply
No module named 'transformers' (install transformers itself first)
Versions
any transformers with fast tokenizers
Why it happens
Fast tokenizers are implemented in Rust in the separate tokenizers package; minimal installs skip it.
Edge cases
conda users: conda install -c conda-forge tokenizers avoids Rust-toolchain build issues.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.