在用python编写的azure函数应用程序中使用librosa

2024-05-19 00:24:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在python中使用一个azure函数,它使用librosa来可视化一些音频数据。它可以在vscode中的我的windows box上本地正常工作。使用从命令行远程生成

func azure functionapp publish functionappname --build remote

成功,但当客户端向其发布数据时,它会失败

OSError: sndfile library not found

File "/home/site/wwwroot/VisualizeDemo/__init__.py", line 20, in <module> import librosa 
File "/home/site/wwwroot/.python_packages/lib/site-packages/librosa/__init__.py", line 12, in <module> from . import core 
File "/home/site/wwwroot/.python_packages/lib/site-packages/librosa/core/__init__.py", line 126, in <module> from .audio import * # pylint: disable=wildcard-import 
File "/home/site/wwwroot/.python_packages/lib/site-packages/librosa/core/audio.py", line 10, in <module> import soundfile as sf 
File "/home/site/wwwroot/.python_packages/lib/site-packages/soundfile.py", line 142, in <module> raise OSError('sndfile library not found')

我知道librosa依赖libsndfile

pip install librosa

还将在我的本地服务器上安装libsndfile,并且我上传到azure的控制盘中不包含该libsndfile。我跑

apt-get install libsndfile1

在函数主机上,在那里安装库,这似乎已经成功:

root@7d0b717a5bb5:/home/site/wwwroot# apt-get install libsndfile1
Reading package lists... Done
Building dependency tree
Reading state information... Done
libsndfile1 is already the newest version (1.0.28-6).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

但是函数仍然找不到它。是否有其他方法安装libsndfile以使其对函数可见,或者告诉函数在何处查找该库?功能应用程序按照常规应用程序服务计划运行,而非无服务器消费计划


Tags: 函数inpyimporthomelibpackagesline
2条回答
  1. root@7d0b717a5bb5:/home/site/wwwroot# apt-get update
  1. root@7d0b717a5bb5:/home/site/wwwroot# apt-get install g++
  1. root@7d0b717a5bb5:/home/site/wwwroot# apt-get install libsndfile1
  1. root@7d0b717a5bb5:/home/site/wwwroot# pip install librosa

以上命令是我的猜测。如果apt-get install libsndfile1提供的命令正确,您的问题应该得到解决。

因为我以前也遇到过类似的问题,我的答案可以很好的解决。建议您尝试一下,您也可以提供一个示例演示或参考文档,这样我就可以在我的环境中进行测试,更好地帮助您

有关更多详细信息,请参阅下面的帖子

How to access ODBC Driver on Azure App service

默认情况下,Linux上的Azure函数在默认容器中运行。因此,在函数主机中通过apt-get install libsndfile1安装将不会影响容器中的内容。对于这样的场景,您应该考虑Creating function using a custom container

  • 您可以从here为python使用函数基映像
  • 在上面提供的docker文件中,您将看到几个apt-get安装,具体取决于您选择的映像。只需添加所需的依赖项(libsndfile1在本例中)
  • 构建并部署引用guide的函数

注意:消费计划中不支持自定义映像。它需要高级计划或专用(应用程序服务)计划

相关问题 更多 >

    热门问题