You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pip安装sentence-transformers遇元数据准备错误,求解决方案

安装sentence-transformers时出现sentencepiece元数据生成失败(WinError 2)

尝试通过pip安装sentence-transformers包时,触发以下错误:

Collecting sentence-transformers
  Using cached sentence_transformers-2.3.1-py3-none-any.whl.metadata (11 kB)
Collecting transformers<5.0.0,>=4.32.0 (from sentence-transformers)
  File was already downloaded c:\users\administrateur.win-87mr2krtigi\desktop\python\llama-index\transformers-4.37.2-py3-none-any.whl
Collecting tqdm (from sentence-transformers)
  File was already downloaded c:\users\administrateur.win-87mr2krtigi\desktop\python\llama-index\tqdm-4.66.1-py3-none-any.whl
Collecting torch>=1.11.0 (from sentence-transformers)
  File was already downloaded c:\users\administrateur.win-87mr2krtigi\desktop\python\llama-index\torch-2.2.0-cp312-cp312-win_amd64.whl
Collecting numpy (from sentence-transformers)
  File was already downloaded c:\users\administrateur.win-87mr2krtigi\desktop\python\llama-index\numpy-1.26.3-cp312-cp312-win_amd64.whl
Collecting scikit-learn (from sentence-transformers)
  Using cached scikit_learn-1.4.0-1-cp312-cp312-win_amd64.whl.metadata (11 kB)
Collecting scipy (from sentence-transformers)
  Using cached scipy-1.12.0-cp312-cp312-win_amd64.whl.metadata (60 kB)
Collecting nltk (from sentence-transformers)
  File was already downloaded c:\users\administrateur.win-87mr2krtigi\desktop\python\llama-index\nltk-3.8.1-py3-none-any.whl
Collecting sentencepiece (from sentence-transformers)
  Using cached sentencepiece-0.1.99.tar.gz (2.6 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [17 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Administrateur.WIN-87MR2KRTIGI\AppData\Local\Temp\2\pip-download-eylr7dz3\sentencepiece_c76fcda444de4973979ae3fb5a19c9b8\setup.py", line 126, in <module>
          subprocess.check_call([
        File "C:\Program Files\Python312\Lib\subprocess.py", line 408, in check_call
          retcode = call(*popenargs, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Program Files\Python312\Lib\subprocess.py", line 389, in call
          with Popen(*popenargs, **kwargs) as p:
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Program Files\Python312\Lib\subprocess.py", line 1026, in __init__
          self._execute_child(args, executable, preexec_fn, close_fds,
        File "C:\Program Files\Python312\Lib\subprocess.py", line 1538, in _execute_child
          hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

当前已安装包列表

aiohttp                   3.9.3
aiosignal                 1.3.1
annotated-types           0.6.0
anyio                     4.2.0
attrs                     23.2.0
build                     1.0.3
CacheControl              0.13.1
certify                   2023.11.17
charset-normalizer        3.3.2
cleo                      2.1.0
click                     8.1.7
Colorama                  0.4.6
crashtest                 0.4.1
dataclasses-json          0.6.3
Deprecated                1.2.14
dirtyjson                 1.0.8
diskcache                 5.6.3
distlib                   0.3.8
distro                    1.9.0
dulwich                   0.21.7
fastjsonschema            2.19.1
filelock                  3.13.1
frozenlist                1.4.1
fsspec                    2023.12.2
greenlet                  3.0.3
h11                       0.14.0
httpcore                  1.0.2
httpx                     0.26.0
huggingface-hub           0.20.3
idna                      3.6
installer                 0.7.0
jaraco.classes            3.3.0
Jinja2                    3.1.3
joblib                    1.3.2
jsonschema                4.21.1
jsonschema-specifications 2023.12.1
keyring                   24.3.0
llama_cpp_python          0.2.38
llama-index               0.9.40
MarkupSafe                2.1.4
marshmallow               3.20.2
more-itertools            10.2.0
mpmath                    1.3.0
msgpack                   1.0.7
multidict                 6.0.4
mypy-extensions           1.0.0
nest-asyncio              1.6.0
networkx                  3.2.1
nltk                      3.8.1
numpy                     1.26.3
openai                    1.10.0
packaging                 23.2
pandas                    2.2.0
pathspec                  0.12.1
pexpect                   4.9.0
pillow                    10.2.0
pip                       23.3.2
pkginfo                   1.9.6
platformdirs              3.11.0
poetry                    1.7.1
poetry-core               1.8.1
poetry-plugin-export      1.6.0
ptyprocess                0.7.0
pydantic                  2.6.0
pydantic_core             2.16.1
pyproject_hooks           1.0.0
pyproject-metadata        0.7.1
pyproject-toml            0.0.10
python-dateutil           2.8.2
pytz                      2023.4
pywin32-ctypes            0.2.2
PyYAML                    6.0.1
rapidfuzz                 3.6.1
referencing               0.33.0
regex                     2023.12.25
requests                  2.31.0
requests-toolbelt         1.0.0
rpds-py                   0.17.1
safetensors               0.4.2
scikit_build_core         0.8.0
setuptools                69.0.3
shellingham               1.5.4
six                       1.16.0
sniffio                   1.3.0
SQLAlchemy                2.0.25
sympy                     1.12
tenacity                  8.2.3
tiktoken                  0.5.2
tokenizers                0.15.1
toml                      0.10.2
tomlkit                   0.12.3
torch                     2.2.0
torchvision               0.17.0
tqdm                      4.66.1
transformers              4.37.2
trove-classifiers         2024.1.8
typing_extensions         4.9.0
typing-inspect            0.9.0
tzdata                    2023.4
urllib3                   2.2.0
virtualenv                20.25.0
wheel                     0.42.0
wrapt                     1.16.0
yarl                      1.9.4

已更新/安装的包

  • llama_cpp_python
  • multidict
  • numpy
  • pip
  • pyproject-toml
  • scikit_build_core
  • setuptools
  • torch
  • torchvision
  • transformers
  • wheel

解决方案

错误根源是sentencepiece 0.1.99版本尝试从源码编译时找不到编译工具,或该版本未适配Python3.12的预编译包。可通过以下步骤解决:

  1. 优先安装预编译的sentencepiece包
    强制pip使用预编译wheel包,避免源码编译:

    pip install sentencepiece==0.1.99 --only-binary :all:
    

    若上述命令失败,说明该版本无对应Python3.12的预编译包,尝试安装更高版本:

    pip install sentencepiece>=0.2.0
    
  2. 重新安装sentence-transformers
    安装好sentencepiece后,执行:

    pip install sentence-transformers
    
  3. 备选方案:安装C++编译工具
    若必须从源码编译,需安装Visual Studio Build Tools(勾选"Desktop development with C++"组件),再重新尝试安装。但预编译包方案更简便。


内容的提问来源于stack exchange,提问作者Samuel Flahaut

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 02:12:04