如何在heroku上使用声音文件

kev*_*son 3 python heroku python-3.x

我有一个在 Heroku 上运行的 python flask 应用程序,它使用了soundfile。添加soundfilerequirements.txtHeroku 后给了我这个错误:

raise OSError('sndfile library not found')
Run Code Online (Sandbox Code Playgroud)

查了一下,读到我需要libsndfile1导入库。但是当我也将其添加到时requirements.txt,构建失败并出现错误:

找不到与 libsndfile1 匹配的发行版

是否有导入此包的解决方法,以便我可以soundfile在 Heroku 上使用?

Chr*_*ris 6

libsndfile1不是 Python 库,因此您无法通过requirements.txt.

实现此功能的一种方法是将aptbuildpack与 Python buildpack 一起使用:

  1. 删除libsndfile1从您的requirements.txt

  2. 将您的应用程序配置为使用两个构建包:

    heroku buildpacks:set heroku/python
    heroku buildpacks:add --index 1 heroku-community/apt
    heroku buildpacks
    # Should show apt first, then python
    
    Run Code Online (Sandbox Code Playgroud)
  3. 添加Aptfile要安装的 Ubuntu 软件包列表:

    libsndfile1
    
    Run Code Online (Sandbox Code Playgroud)
  4. 提交您的更改并推送部署。您应该apt首先看到安装的包,然后是常规的 Python 部署。

  • @kevinchristianson 您是否尝试将 `libsndfile-dev` 添加到 `Aptfile` 中? (6认同)
  • 谢谢,这似乎正是我正在寻找的!不幸的是,我尝试了一下,Heroku 显示在构建中安装了 `libsndfile1`,但是当它尝试部署时,我得到了相同的错误:`File "/app/.heroku/python/lib/python3.7/site-packages/soundfile .py”,第 142 行,在 <module> 中引发 OSError('sndfile 库未找到')` (2认同)