How to Install tiktoken in Python
tiktoken is a fast BPE tokeniser for use with OpenAI's models
pip install tiktoken
What is tiktoken?
tiktoken is a fast BPE tokeniser for use with OpenAI's models
tiktoken is a fast BPE tokeniser for use with OpenAI's models.
The open source version of can be installed from PyPI:
Example code using can be found in the OpenAI Cookbook.
Quick Start
Minimal example to get started with tiktoken:
import tiktoken
print(tiktoken.__version__)
Installation
pip (standard)
pip install tiktoken
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install tiktoken
pip3
pip3 install tiktoken
conda
conda install -c conda-forge tiktoken
Poetry
poetry add tiktoken
Dependencies
Installing tiktoken will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import tiktoken; print(tiktoken.__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 tiktoken with pip.
ModuleNotFoundError: No module named 'tiktoken'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install tiktoken. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'tiktoken' (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 tiktoken to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'tiktoken'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show tiktoken and upgrade with pip install --upgrade tiktoken.
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 tiktoken. 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 tiktoken
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 tiktoken
Recent Releases
| Version | Released |
|---|---|
0.12.0 latest |
2025-10-06 |
0.11.0 |
2025-08-08 |
0.10.0 |
2025-08-05 |
0.9.0 |
2025-02-14 |
0.8.0 |
2024-10-03 |
Manage tiktoken
Upgrade to latest version
pip install --upgrade tiktoken
Install a specific version
pip install tiktoken==0.12.0
Uninstall
pip uninstall tiktoken
Check what is installed
pip show tiktoken