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

如何修复module 'fluidsynth' has no attribute 'Synth'报错

执行pm.fluidsynth()时出现"module 'fluidsynth' has no attribute 'Synth'"报错的解决思路

问题场景

在跟随TensorFlow音乐生成教程时,运行代码waveform = pm.fluidsynth(fs=_SAMPLING_RATE)触发报错:module 'fluidsynth' has no attribute 'Synth'。使用PyCharm,所有依赖包安装在单个虚拟环境中,已尝试以下方案但未解决:

  • 安装了pip install pyfluidsynth(版本1.23.5)和pip install fluidsynth(版本0.2);
  • 尝试了Stack Overflow上的旧版本解决方案,但无效;
  • 执行print(fluidsynth.__version__)时,提示module 'fluidsynth' has no attribute '__version__'。

解决步骤

  1. 清理冲突包
    同时安装pyfluidsynth和fluidsynth会导致命名冲突,先彻底卸载两个包:

    pip uninstall -y pyfluidsynth fluidsynth
    

    仅重新安装pyfluidsynth:

    pip install pyfluidsynth==1.23.5
    
  2. 验证包的可用性
    在PyCharm的虚拟环境终端中运行以下代码,确认pyfluidsynth的Synth类可正常访问:

    import pyfluidsynth as fluidsynth
    print(fluidsynth.__version__)
    synth = fluidsynth.Synth()
    

    若这段代码无报错,说明包本身正常,问题出在pretty_midi的调用逻辑上。

  3. 修正pretty_midi的fluidsynth绑定
    pretty_midi默认尝试导入原生fluidsynth包,可手动强制它使用pyfluidsynth:
    在调用pm.fluidsynth()前添加如下代码:

    import pyfluidsynth
    import pretty_midi as pm
    pm.pretty_midi.fluidsynth = pyfluidsynth
    
  4. 检查系统级依赖
    pyfluidsynth依赖系统级的FluidSynth库,需确保系统已安装:

    • Windows:下载FluidSynth二进制包,解压后将包含fluidsynth.dll的目录添加到系统环境变量PATH;
    • macOS:通过Homebrew执行brew install fluidsynth;
    • Linux(Debian/Ubuntu):执行sudo apt-get install fluidsynth。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 14:12:15