我有一个python flask应用程序,我在Heroku上运行,它使用soundfile
库。将soundfile
添加到requirements.txt
Heroku 给了我这个错误:
raise OSError('sndfile library not found')
我查了一下,读到我需要导入libsndfile1
库。但是当我将其添加到requirements.txt
时,构建失败并出现错误:
找不到 libsndfile1 的匹配发行版
是否有导入此软件包的解决方法,以便我可以在 Heroku 上使用soundfile
?
libsndfile1
不是Python库,因此您无法通过requirements.txt
安装它。
实现此功能的一种方法是将apt
构建包与 Python 构建包一起使用:
从
requirements.txt
中删除libsndfile1
将应用程序配置为使用两个构建包:
heroku buildpacks:set heroku/python heroku buildpacks:add --index 1 heroku-community/apt heroku buildpacks # Should show apt first, then python
添加一个列出要安装的 Ubuntu 软件包的
Aptfile
:libsndfile1
您可能还需要在此文件中包含
libsndfile-dev
或libsndfile1-dev
,每个依赖项都有自己的行,具体取决于您使用的 Heroku 堆栈,例如libsndfile1 libsndfile1-dev
提交更改并推送到部署。您应该会看到首先安装
apt
包,然后是常规 Python 部署。
创建一个"Aptfile"并添加以下行:
libasound2-dev python-dev python-numpy python-setuptools libsndfile-dev
这对我有用。