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

运行Hello Magenta Colab笔记本时出现'metadata-generation-failed'错误的求助

运行Hello Magenta Colab笔记本时出现'metadata-generation-failed'错误的求助

我完全懂你现在的困扰——这个官方的Hello Magenta Colab笔记本确实因为Colab环境的迭代变得过时了,从你贴的错误日志能看到两个核心问题:

  • 当前Colab用的是Ubuntu 22.04系统,默认源里已经找不到libfluidsynth2这个包了,直接报了E: Package 'libfluidsynth2' has no installation candidate的错误
  • 直接安装最新版Magenta时,因为和当前Colab的Python、TensorFlow版本不兼容,触发了python setup.py egg_info did not run successfully的元数据生成失败问题

下面是实测有效的修复方案,直接替换原来的代码块运行即可:

修复后的完整代码

print('Installing dependencies...')
# 适配Ubuntu 22.04源,替换过时的libfluidsynth2为libfluidsynth3
!apt-get update -qq && apt-get install -qq libfluidsynth3 fluid-soundfont-gm build-essential libasound2-dev libjack-dev
!pip install -qU pyfluidsynth pretty_midi

# 指定和Colab环境兼容的Magenta稳定版本,避免版本冲突
!pip install -qU magenta==2.1.1

# 修复Colab环境下的fluidsynth库路径识别问题
import ctypes.util
orig_ctypes_util_find_library = ctypes.util.find_library
def proxy_find_library(lib):
  if lib == 'fluidsynth':
    # 对应libfluidsynth3的库文件名
    return 'libfluidsynth.so.3'
  else:
    return orig_ctypes_util_find_library(lib)
ctypes.util.find_library = proxy_find_library

print('Importing libraries and defining some helper functions...')
from google.colab import files

import magenta
import note_seq
import tensorflow

print(' Done!')
print(magenta.__version__)
print(tensorflow.__version__)

为什么这些修改能解决问题?

  1. 替换fluidsynth包版本:Colab的Ubuntu系统从旧版升级到22.04后,官方源里的fluidsynth包已经更新到libfluidsynth3,原来的libfluidsynth2已经被移除,所以必须替换才能正常安装。
  2. 锁定Magenta版本:最新的Magenta开发版还没适配Colab的TensorFlow 2.x环境,而magenta==2.1.1是经过测试的稳定版本,能完美兼容当前Colab的Python和TensorFlow版本,解决元数据生成失败的问题。
  3. 更新库路径代理:新安装的libfluidsynth3对应的库文件名是libfluidsynth.so.3,所以要修改代理函数的返回值,确保Python能正确找到这个库。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 08:43:01