问题
I have a python flask app I'm running on Heroku which uses the soundfile library. After adding soundfile to requirements.txt Heroku gave me this error:
raise OSError('sndfile library not found')
I looked it up and read that I needed the libsndfile1 library imported. But when I added that to the requirements.txt as well, the build failed with the error:
No matching distribution found for libsndfile1
Is there a workaround for importing this package so I can use soundfile on Heroku?
回答1:
libsndfile1 isn't a Python library, so you can't install it via requirements.txt.
One way to get this working is to use the apt buildpack alongside the Python buildpack:
Remove
libsndfile1from yourrequirements.txtConfigure your application to use two buildpacks:
heroku buildpacks:set heroku/python heroku buildpacks:add --index 1 heroku-community/apt heroku buildpacks # Should show apt first, then pythonAdd an Aptfile listing Ubuntu packages to be installed:
libsndfile1Commit your changes and push to deploy. You should see
aptpackages installed first, then your regular Python deployment.
回答2:
Create an 'Aptfile' and add the following lines:
libasound2-dev python-dev python-numpy python-setuptools libsndfile-dev
This worked for me.
来源:https://stackoverflow.com/questions/57743005/how-to-use-soundfile-on-heroku