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

Windows下Python3.9安装Magenta遇编译错误求助

Windows下Python3.9.13安装Magenta失败:numba、llvmlite、python-rtmidi构建wheel出错

在Windows系统的Python3.9.13环境中,使用pip安装Magenta时,numba、llvmlite和python-rtmidi包的wheel构建失败,具体错误日志如下:

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [13 lines of output]
    running bdist_wheel
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-cpython-39
    creating build\lib.win-amd64-cpython-39\rtmidi
    copying rtmidi\midiconstants.py -> build\lib.win-amd64-cpython-39\rtmidi
    copying rtmidi\midiutil.py -> build\lib.win-amd64-cpython-39\rtmidi
    copying rtmidi\release.py -> build\lib.win-amd64-cpython-39\rtmidi
    copying rtmidi\__init__.py -> build\lib.win-amd64-cpython-39\rtmidi
    running build_ext
    building 'rtmidi._rtmidi' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for python-rtmidi
Running setup.py clean for python-rtmidi
Building wheel for llvmlite (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [40 lines of output]
    running bdist_wheel
    C:\Users\Dell\anaconda3\python.exe C:\Users\Dell\AppData\Local\Temp\pip-install-f301n_gf\llvmlite_52e74a978a1540339621403e230729a1\ffi\build.py
    -- Selecting Windows SDK version  to target Windows 10.0.19044.
    CMake Error at CMakeLists.txt:3 (project):
      Failed to run MSBuild command:

        MSBuild.exe

      to get the value of VCTargetsPath:

        Das System kann die angegebene Datei nicht finden



    -- Configuring incomplete, errors occurred!
    See also "C:/Users/Dell/AppData/Local/Temp/tmpjza6m78t/CMakeFiles/CMakeOutput.log".
    CMake Error at CMakeLists.txt:3 (project):
      Generator

        Visual Studio 15 2017 Win64

      could not find any instance of Visual Studio.



    -- Configuring incomplete, errors occurred!
    See also "C:/Users/Dell/AppData/Local/Temp/tmp0ap85972/CMakeFiles/CMakeOutput.log".
    Trying generator 'Visual Studio 14 2015 Win64'
    Trying generator 'Visual Studio 15 2017 Win64'
    Traceback (most recent call last):
      File "C:\Users\Dell\AppData\Local\Temp\pip-install-f301n_gf\llvmlite_52e74a978a1540339621403e230729a1\ffi\build.py", line 192, in <module>
        main()
      File "C:\Users\Dell\AppData\Local\Temp\pip-install-f301n_gf\llvmlite_52e74a978a1540339621403e230729a1\ffi\build.py", line 180, in main
        main_win32()
      File "C:\Users\Dell\AppData\Local\Temp\pip-install-f301n_gf\llvmlite_52e74a978a1540339621403e230729a1\ffi\build.py", line 89, in main_win32
        generator = find_win32_generator()
      File "C:\Users\Dell\AppData\Local\Temp\pip-install-f301n_gf\llvmlite_52e74a978a1540339621403e230729a1\ffi\build.py", line 85, in find_win32_generator
        raise RuntimeError("No compatible cmake generator installed on this machine")
    RuntimeError: No compatible cmake generator installed on this machine
    error: command 'C:\\Users\\Dell\\anaconda3\\python.exe' failed with exit code 1
    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for llvmlite
Running setup.py clean for llvmlite
Failed to build numba python-rtmidi llvmlite
Installing collected packages: python-rtmidi, pygtrie, mido, llvmlite, keras, flatbuffers, tensorflow-estimator, sox, scipy, protobuf, promise, numba, keras-preprocessing, importlib_resources, imageio, etils, absl-py, tf-slim, tensorflow-probability, sk-video, resampy, mir-eval, matplotlib, googleapis-common-protos, dm-sonnet, tensorflow-metadata, librosa, tensorflow-datasets, tensorboard, note-seq, tensorflow, magenta
  Running setup.py install for python-rtmidi ... error
  error: subprocess-exited-with-error

  × Running setup.py install for python-rtmidi did not run successfully.
  │ exit code: 1
  ╰─> [15 lines of output]
      running install
      C:\Users\Dell\anaconda3\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-39
      creating build\lib.win-amd64-cpython-39\rtmidi
      copying rtmidi\midiconstants.py -> build\lib.win-amd64-cpython-39\rtmidi
      copying rtmidi\midiutil.py -> build\lib.win-amd64-cpython-39\rtmidi
      copying rtmidi\release.py -> build\lib.win-amd64-cpython-39\rtmidi
      copying rtmidi\__init__.py -> build\lib.win-amd64-cpython-39\rtmidi
      running build_ext
      building 'rtmidi._rtmidi' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> python-rtmidi

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

已尝试以下方法但均无效:

  • 重装numba、llvmlite、python-rtmidi这三个包
  • 降级上述包的版本
  • 调整cmake和wheel包的版本
  • 安装Windows SDK
  • 在其他设备上测试

解决方案

1. 安装完整的Microsoft C++ Build Tools

错误日志明确提示缺少Visual C++ 14.0+工具链和兼容的CMake生成器,需安装完整的构建工具:

  • 打开Microsoft C++ Build Tools安装器,勾选桌面开发C++ workload,该组件包含MSBuild、VC++编译器、Windows SDK等必要构建依赖
  • 确保选择与Python版本匹配的架构(x64,日志显示为win-amd64)
  • 安装完成后重启电脑,保证环境变量生效

2. 使用预编译wheel包跳过本地编译

如果不想安装构建工具,可以直接使用第三方提供的预编译wheel包:

  • 下载对应Python3.9 x64版本的python-rtmidi、llvmlite、numba wheel文件
  • 用pip本地安装这些wheel:
    pip install python_rtmidi-*.whl llvmlite-*.whl numba-*.whl
    
  • 再执行Magenta安装:
    pip install magenta
    

3. 验证MSBuild环境变量

安装构建工具后,确认MSBuild路径已加入系统PATH:

  • 检查路径是否存在(示例路径:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin)
  • 打开新的命令提示符,输入msbuild,确认命令能正常执行,无报错

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 14:01:42