【问题标题】:I am getting "OSError: sndfile library not found" & "Unable to locate package libsndfile1" errors when deploying audio prediction model on Heroku在 Heroku 上部署音频预测模型时出现“OSError: sndfile library not found”和“Unable to locate package libsndfile1”错误
【发布时间】:2020-10-01 20:49:37
【问题描述】:

目标是在 Heroku 上部署音频预测 ML 模型,该模型使用来自 python 的 librosa 库。

app.py 文件使用 librosa 库从音频中提取特征。

当我尝试在 Heroku 上部署时,我收到如下所示的错误。

2020-06-12T03:27:43.099874+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/librosa/core/audio.py", line 10, in <module>
2020-06-12T03:27:43.099875+00:00 app[web.1]:     import soundfile as sf
2020-06-12T03:27:43.099875+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/soundfile.py", line 142, in <module>
2020-06-12T03:27:43.099876+00:00 app[web.1]:     raise OSError('sndfile library not found')
2020-06-12T03:27:43.099876+00:00 app[web.1]: OSError: sndfile library not found
2020-06-12T03:27:43.101008+00:00 app[web.1]: [2020-06-12 03:27:43 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-06-12T03:27:43.255623+00:00 app[web.1]: [2020-06-12 03:27:43 +0000] [4] [INFO] Shutting down: Master
2020-06-12T03:27:43.255725+00:00 app[web.1]: [2020-06-12 03:27:43 +0000] [4] [INFO] Reason: Worker failed to boot.
2020-06-12T03:27:43.333827+00:00 heroku[web.1]: Process exited with status 3
2020-06-12T03:27:43.371190+00:00 heroku[web.1]: State changed from starting to crashed

这是我用来安装依赖项的 buildpack 的快照: Build pack list

下面是 requirements.txt 中提到的依赖列表:

Flask==1.1.1
gunicorn==19.9.0
itsdangerous==1.1.0
Jinja2==2.10.1
MarkupSafe==1.1.1
Werkzeug==0.15.5
numpy>=1.9.2
scipy>=0.15.1
scikit-learn>=0.18
matplotlib>=1.4.3
pandas>=0.19
librosa==0.7.2
aniso8601==8.0.0
audioread==2.1.5

我还创建了一个 Aptfile 来安装 libsndfile1。我已经在 Heroku 上链接了一个构建包以从这个 Aptfile 安装。以下是我的 Aptfile 中提到的列表:

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

这是在 Heroku 上部署时出现错误 "Unable to locate package libsndfile1" 的图像

如何克服“OSError: sndfile library not found”和“Unable to locate package libsndfile1”错误?

我已将所有文件上传到 GitHub here 以获取更多信息。


更新(2020 年 12 月 14 日):我更改了我的 Aptfile 和 requirements.txt 内容,它起作用了。

以下是 Aptfile 的内容:

libsndfile1
libsndfile-dev
ffmpeg

以下是 Aptfile 的内容:

aniso8601==8.0.0
audioread==2.1.8
certifi==2019.11.28
cffi==1.14.0
Click==7.0
decorator==4.4.2
ffmpeg-python==0.2.0
Flask==1.1.1
Flask-RESTful==0.3.8
future==0.18.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.1
joblib==0.14.1
librosa==0.7.2
llvmlite==0.31.0
MarkupSafe==1.1.1
marshmallow==3.2.2
numba==0.48.0
numpy==1.18.1
pycparser==2.20
pydub==0.23.1
pytz==2019.3
resampy==0.2.2
scikit-learn==0.22.2.post1
scipy==1.4.1
six==1.14.0
SoundFile==0.10.3.post1
Werkzeug==1.0.0
wincertstore==0.2
pandas==1.0.1
pathlib==1.0.1

【问题讨论】:

    标签: python flask heroku deployment librosa


    【解决方案1】:

    您需要将sndfile 作为一个软件包安装到您的操作系统中。 This answer 记录了如何在 Heroku 上执行此操作。

    【讨论】:

    • 谢谢。 Chris 来自该链接的解决方案对我有用。现在我收到一个名为ModuleNotFoundError: No module named 'numba.decorators' 的不同错误。请问这个错误有什么帮助吗?
    • 谢谢。我使用该链接将numba==0.48 添加到我的requirements.txt 文件中。我得到相同的OSError: sndfile library not found 下面是错误的详细日志。 2020-06-15T20:50:33.505234+00:00 app[web.1]: import soundfile as sf 2020-06-15T20:50:33.505234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/soundfile.py", line 142, in &lt;module&gt; 2020-06-15T20:50:33.505235+00:00 app[web.1]: raise OSError('sndfile library not found') 2020-06-15T20:50:33.505235+00:00 app[web.1]: OSError: sndfile library not found
    • 听起来您已经使用 AptFile 恢复了修复
    • 谢谢。我改变了我的 apt-file 和 requirements 文件。我已经用什么帮助了我更新了这个问题。感谢您的支持。我很感激。
    猜你喜欢
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-27
    相关资源
    最近更新 更多