Unable to install sentencepiece on Python 3.12
When I run pip install sentencepiece, I get the following error:
Collecting sentencepiece
Using cached sentencepiece-0.1.99.tar.gz (2.6 MB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: sentencepiece
Building wheel for sentencepiece (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [62 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-312
creating build/lib.linux-x86_64-cpython-312/sentencepiece
copying src/sentencepiece/__init__.py -> build/lib.linux-x86_64-cpython-312/sentencepiece
copying src/sentencepiece/_version.py -> build/lib.linux-x86_64-cpython-312/sentencepiece
copying src/sentencepiece/sentencepiece_model_pb2.py -> build/lib.linux-x86_64-cpython-312/sentencepiece
copying src/sentencepiece/sentencepiece_pb2.py -> build/lib.linux-x86_64-cpython-312/sentencepiece
running build_ext
/bin/sh: 1: pkg-config: Permission denied
./build_bundled.sh: 21: cmake: Permission denied
./build_bundled.sh: 22: cmake: Permission denied
...
subprocess.CalledProcessError: Command '['./build_bundled.sh', '0.1.99']' returned non-zero exit status 127.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for sentencepiece
Running setup.py clean for sentencepiece
Failed to build sentencepiece
ERROR: Could not build wheels for sentencepiece, which is required to install pyproject.toml-based projects
So it seems like the installation process of sentencepiece calls a build_bundled.sh script, which internally uses cmake, for which permission is denied.
System information
Python: 3.12.0 OS: Ubuntu 22.04.3
Notes
I think this issue is specific to Python 3.12: pip install sentencepiece works for me in a Python 3.11 environment.
I think this may be related to the removal of distutils from Python 3.12 (see PEP 632).
Not sure if you are willing to consider conda, but we've had 3.12 builds of sentencepiece in conda-forge for almost two month now.
conda install -c conda-forge sentencepiece
It worked for me after installing and removing cmake as a pip package. Here's a wheel, in case its useful: sentencepiece-0.1.99-cp312-cp312-linux_x86_64.whl.zip
Fixed in v0.2.0
py3.13 not work
found any solution for 3.13, or we just wait?
Solution for Python 3.13
The error is caused by CMake broken compatibility with it's previous version (the minimum version supported is 3.5). So the solution is to install a previous version to compile correctly. As this output says:
Package sentencepiece was not found in the pkg-config search path.
Perhaps you should add the directory containing `sentencepiece.pc'
to the PKG_CONFIG_PATH environment variable
Package 'sentencepiece', required by 'virtual:world', not found
CMake Error at CMakeLists.txt:15 (cmake_minimum_required):
Compatibility with CMake < 3.5 has been removed from CMake.
Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
-- Configuring incomplete, errors occurred!
The solution is to install CMake with version 3.27 (pip3 install cmake==3.27) (that worked for me on python 3.13.2).
$ pip3 list
Package Version
------------------------- --------------
accelerate 1.6.0
...
bitsandbytes 0.45.4
...
cmake 3.27.0
...
flash_attn 2.7.4.post1
...
...
numpy 2.2.4
...
pip 25.0
...
safetensors 0.5.3
...
sentencepiece 0.2.0
setuptools 78.1.0
...
tokenizers 0.21.1
torch 2.6.0
...
transformers 4.50.3
...
$ python3 --version
Python 3.13.2
I hope this can help!
@simonecocco Thank you very much for the solution! I had the same issue for the Python 3.13 but It works for me too
BTW, Mac Sonoma 14.6.1. Conda
% python --version
Python 3.13.2
cmake==3.27 didn't work for me to build in docker on macbook arm with Python 3.13
What worked for me:
uv pip install cmake==3.31.6
uv pip install sentencepiece
MacOS 15.4.1 Python 3.13.1
What worked for me:
uv pip install cmake==3.31.6 uv pip install sentencepieceMacOS 15.4.1 Python 3.13.1
Works like a charm
What worked for me:
uv pip install cmake==3.31.6 uv pip install sentencepieceMacOS 15.4.1 Python 3.13.1
This solved my issue perfectly!
Macbook pro MacOS: 14.6 Python 3.13.2
Package Version
accelerate 1.6.0 certifi 2025.4.26 charset-normalizer 3.4.2 cmake 3.31.6 ............ ............ ............
Building wheels for collected packages: sentencepiece Building wheel for sentencepiece (pyproject.toml) ... error error: subprocess-exited-with-error
× Building wheel for sentencepiece (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [129 lines of output] ............................. ............................ .............................. ............................... subprocess.CalledProcessError: Command '['./build_bundled.sh', '0.2.0']' returned non-zero exit status 1. [end of output]
note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for sentencepiece Failed to build sentencepiece ERROR: Failed to build installable wheels for some pyproject.toml based projects (sentencepiece)
Tried several suggestions. Nothing works.
same here:
macos: 15.4.1 Python 3.13.2
tried different cmake versions 3.27.0, 3.31.6
none works
What worked for me:
uv pip install cmake==3.31.6 uv pip install sentencepieceMacOS 15.4.1 Python 3.13.1
works for me, but can't believe that have to use uv, overcomplicated
nuibility, windows
pip install cmake==3.27 pip install sentencepiece
python 3.13.3
What worked for me:
uv pip install cmake==3.31.6 uv pip install sentencepieceMacOS 15.4.1 Python 3.13.1
works for me, but can't believe that have to use uv, overcomplicated
You don't have to, it's just quicker.
with suggestions from chatgpt macOS Tahoe 26 Beta, Python 3.13.1
pip install cmake==3.31.6
pip install --upgrade pip setuptools wheel
pip install sentencepiece
works for me, niubi ,,,
The workaround of installing cmake with pip isn't working for me. Here's the one that worked for me:
CXXFLAGS="-include cstdint" CMAKE_POLICY_VERSION_MINIMUM=3.5 pip install sentenpiece
The CXXFLAGS="-include cstdint" may or may not be needed depending on the GCC version you've got on your system. See https://github.com/google/sentencepiece/issues/1108
The workaround of installing cmake with pip isn't working for me. Here's the one that worked for me:
CXXFLAGS="-include cstdint" CMAKE_POLICY_VERSION_MINIMUM=3.5 pip install sentenpieceThe
CXXFLAGS="-include cstdint"may or may not be needed depending on the GCC version you've got on your system. See #1108
Worked for me, thanks.