如何在 heroku 上使用声音文件



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

raise OSError('sndfile library not found')

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

找不到 libsndfile1 的匹配发行版

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

libsndfile1

不是Python库,因此您无法通过requirements.txt安装它。

实现此功能的一种方法是将apt构建包与 Python 构建包一起使用:

  1. requirements.txt中删除libsndfile1

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

    heroku buildpacks:set heroku/python
    heroku buildpacks:add --index 1 heroku-community/apt
    heroku buildpacks
    # Should show apt first, then python
    
  3. 添加一个列出要安装的 Ubuntu 软件包的Aptfile

    libsndfile1
    

    您可能还需要在此文件中包含libsndfile-devlibsndfile1-dev,每个依赖项都有自己的行,具体取决于您使用的 Heroku 堆栈,例如

    libsndfile1
    libsndfile1-dev
    
  4. 提交更改并推送到部署。您应该会看到首先安装apt包,然后是常规 Python 部署。

创建一个"Aptfile"并添加以下行:

libasound2-dev python-dev python-numpy python-setuptools libsndfile-dev

这对我有用。

最新更新