sentencepiece icon indicating copy to clipboard operation
sentencepiece copied to clipboard

Unable to install sentencepiece on Python 3.12

Open enricogandini opened this issue 3 years ago • 19 comments

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).

enricogandini avatar Nov 07 '23 14:11 enricogandini

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

h-vetinari avatar Nov 28 '23 00:11 h-vetinari

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

manueldeprada avatar Feb 01 '24 01:02 manueldeprada

Fixed in v0.2.0

taku910 avatar Feb 19 '24 17:02 taku910

py3.13 not work

yuedu88 avatar Jan 09 '25 18:01 yuedu88

found any solution for 3.13, or we just wait?

beetrandahiya avatar Mar 24 '25 00:03 beetrandahiya

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 avatar Apr 04 '25 12:04 simonecocco

@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

emmanuel-stone avatar Apr 07 '25 09:04 emmanuel-stone

cmake==3.27 didn't work for me to build in docker on macbook arm with Python 3.13

9en9i avatar Apr 18 '25 09:04 9en9i

What worked for me:

uv pip install cmake==3.31.6
uv pip install sentencepiece

MacOS 15.4.1 Python 3.13.1

rovo79 avatar Apr 30 '25 16:04 rovo79

What worked for me:

uv pip install cmake==3.31.6
uv pip install sentencepiece

MacOS 15.4.1 Python 3.13.1

Works like a charm

debasisdev avatar May 01 '25 12:05 debasisdev

What worked for me:

uv pip install cmake==3.31.6
uv pip install sentencepiece

MacOS 15.4.1 Python 3.13.1

This solved my issue perfectly!

rverma6 avatar May 06 '25 19:05 rverma6

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.

zia13 avatar May 06 '25 21:05 zia13

same here:

macos: 15.4.1 Python 3.13.2

tried different cmake versions 3.27.0, 3.31.6

none works

dinge avatar May 09 '25 22:05 dinge

What worked for me:

uv pip install cmake==3.31.6
uv pip install sentencepiece

MacOS 15.4.1 Python 3.13.1

works for me, but can't believe that have to use uv, overcomplicated

MUCZ avatar May 13 '25 05:05 MUCZ

nuibility, windows

pip install cmake==3.27 pip install sentencepiece

python 3.13.3

kevinelstri avatar May 29 '25 01:05 kevinelstri

What worked for me:

uv pip install cmake==3.31.6
uv pip install sentencepiece

MacOS 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.

MuhammadAjmalCoder avatar Jun 03 '25 19:06 MuhammadAjmalCoder

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 ,,,

xingxiajie avatar Jul 20 '25 14:07 xingxiajie

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

SadaleNet avatar Aug 03 '25 15:08 SadaleNet

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 #1108

Worked for me, thanks.

jules-gd-dev avatar Aug 11 '25 21:08 jules-gd-dev