How to use soundfile on heroku

|▌冷眼眸甩不掉的悲伤 提交于 2020-07-28 03:52:25

问题


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:

  1. Remove libsndfile1 from your requirements.txt

  2. Configure 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 python
    
  3. Add an Aptfile listing Ubuntu packages to be installed:

    libsndfile1
    
  4. Commit your changes and push to deploy. You should see apt packages 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!