You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Speechbrain库安装失败求助:sentencepiece编译时CMake报错

Speechbrain库安装失败求助:sentencepiece编译时CMake报错

我在Windows环境下安装SpeechBrain库时,卡在了sentencepiece的源码编译环节,弹出了一堆CMake相关的错误,有没有大佬能帮忙看看怎么解决?

完整错误输出:

Collecting speechbrain
Using cached speechbrain-1.0.2-py3-none-any.whl.metadata (23 kB)
Collecting hyperpyyaml (from speechbrain)
Using cached HyperPyYAML-1.2.2-py3-none-any.whl.metadata (7.6 kB)
Requirement already satisfied: joblib in c:\users\amogh g c\documents\voice_detection.venv\lib\site-packages (from speechbrain) (1.4.2)
Requirement already satisfied: numpy in c:\users\amogh g c\documents\voice_detection.venv\lib\site-packages (from speechbrain) (2.2.1)
Requirement already satisfied: packaging in c:\users\amogh g c\documents\voice_detection.venv\lib\site-packages (from speechbrain) (24.2)
Requirement already satisfied: scipy in c:\users\amogh g c\documents\voice_detection.venv\lib\site-packages (from speechbrain) (1.15.0)
Collecting sentencepiece (from speechbrain)
Using cached sentencepiece-0.2.0.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
╰─> [51 lines of output]
-- Building for: NMake Makefiles
CMake Deprecation Warning at CMakeLists.txt:15 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
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.

  -- VERSION: 0.2.0
  CMake Error at CMakeLists.txt:23 (project):
    Generator

      NMake Makefiles

    does not support platform specification, but platform

      x64

    was specified.

  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "<string>", line 2, in <module>
      exec(compile('''
      ~~~~^^^^^^^^^^^^
      # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ...<31 lines>...
      exec(compile(setup_py_code, filename, "exec"))
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ''' % ('C:\\Users\\...\\AppData\\Local\\Temp\\pip-install-_z6xb03h\\sentencepiece_d547716a6a0f4f0197f65d06be7c0ddd\\setup.py',), "<pip-setuptools-caller>", "exec"))
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<pip-setuptools-caller>", line 34, in <module>
    File "C:\Users\...\AppData\Local\Temp\pip-install-_z6xb03h\sentencepiece_d547716a6a0f4f0197f65d06be7c0ddd\setup.py", line 128, in <module>
      subprocess.check_call([
      ~~~~~~~~~~~~~~~~~~~~~^^
          'cmake',
          ^^^^^^^^
      ...<6 lines>...
          '-DCMAKE_INSTALL_PREFIX=build\\root',
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ])
      ^^
    File "C:\Users\...\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 419, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'sentencepiece', '-A', 'x64', '-B', 'build', '-DSPM_ENABLE_SHARED=OFF', '-DCMAKE_INSTALL_PREFIX=build\\root']' 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: 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.

针对这个问题的解决思路:

1. 补全Windows编译工具链(最推荐)

你的错误核心是Windows下默认用的NMake工具链不支持x64平台编译,且缺少C/C++编译器。解决办法:

  • 下载安装Visual Studio Build Tools,安装时必须勾选「桌面开发用C++」组件(包含MSVC编译器、CMake标准工具链)
  • 安装完成后,不要用普通的cmd/PowerShell,打开开始菜单里的「x64 Native Tools Command Prompt for VS 202X」
  • 在这个专用命令行窗口里激活你的虚拟环境(.\voice_detection.venv\Scripts\activate),再重新运行pip install speechbrain

2. 跳过源码编译,直接装预编译包

如果不想装Build Tools,可以手动安装sentencepiece的预编译wheel包:

  • 确认你的Python版本(比如3.13)和系统位数(x64)
  • 找到对应版本的sentencepiece wheel文件(比如sentencepiece-0.2.0-cp313-cp313-win_amd64.whl
  • 先运行pip install 你下载的wheel文件名.whl,再执行pip install speechbrain

3. 用Conda管理环境(更省心)

如果你的项目用Anaconda/Miniconda,Conda会自动处理编译依赖:

  • 创建并激活环境:conda create -n voice_detection python=3.13 && conda activate voice_detection
  • 安装sentencepiece:conda install -c conda-forge sentencepiece
  • 最后安装SpeechBrain:pip install speechbrain

我自己之前遇到过一模一样的问题,用第一个办法就搞定了,你可以先试试这个~

备注:内容来源于stack exchange,提问作者Amogh GC

火山引擎 最新活动