0

I'm working an an azure function in python that uses librosa to visualize some audio data. It works fine locally on my windows box in vscode. Remote build from the command line with

func azure functionapp publish functionappname --build remote

succeeds, but when a client posts data to it, it fails with

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')

I understand that librosa depends on libsndfile, and that

pip install librosa

also installs libsndfile on my local, and that libsndfile is not included in the wheels I upload to azure. I ran

apt-get install libsndfile1

on the function host, to install the library there, and that seems to have succeeded:

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.

But the function still can't find it. Is there a different way to install libsndfile so it will be visible to the function, or a way to tell the function where to look for that library? The function app is running on a regular app service plan, not the serverless consumption plan.

mpfog
  • 3
  • 3

2 Answers2

0
  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

The above command is my guess. If the command provided by apt-get install libsndfile1 is correct, your problem should be solved.

Because I have encountered similar problems before and my answer can be solved perfectly. It is recommended to try it, and you can also provide a sample demo or reference document, so that I can test in my environment and can better help you.

For more details, you can refer to the below post.

How to access ODBC Driver on Azure App service

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • hi jason. thank you for helping. i ran those commands but still get the same error. it looks like it is triggered by `import librosa` in the function's main __init__.py. when i ran `apt-get install libsndfile1` it said `libsndfile1 is already the newest version (1.0.28-6). 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.` should i have uninstalled libsndfile1 before running these commands? – mpfog Nov 16 '20 at 14:29
  • Can your share your sample code about use librosa, just demo for me to test,tks. – Jason Pan Nov 16 '20 at 14:34
  • You no need to uninstall libsndfile1, you can run command `pip install librosa` directly. – Jason Pan Nov 16 '20 at 14:36
  • If you can provide sample code, I will be able to assist you in solving this problem faster, just provide the fragment code using librosa, which can be uploaded to github. – Jason Pan Nov 16 '20 at 14:38
  • i just made a test function that is just the bare httptrigger template with `import librosa` added under the other imports and it does the same thing. when the library is imported it looks for libsndfile and fails with that message. – mpfog Nov 16 '20 at 15:41
  • i put the files and a readme on git here: https://github.com/markfogarty/azure-function-librosa – mpfog Nov 16 '20 at 16:31
  • I have try to solve it, but failed. You can raise a support ticket for help. – Jason Pan Nov 18 '20 at 01:16
0

By default, Azure Function on Linux runs in a default container. So installing via apt-get install libsndfile1 in the Function host would have no effect on what's inside the container. For such scenario, you should consider Creating function using a custom container.

  • You can use a Function base image for python from here
  • In the docker file provided above, you would see several apt-get installation depending on what image you choose. Just add your required dependency (libsndfile1 in this case).
  • Build and deploy your function referring the guide.

Note: Custom image is not supported in Consumption plan. It would need Premium plan or a Dedicated (App Service) plan.

krishg
  • 5,935
  • 2
  • 12
  • 19