OSError: sndfile library not found

Hi, my app suddenly stopped working and I’m getting the following errors:

On the main page: OSError: sndfile library not found
And my logs are:

Err:1 http://deb.debian.org/debian buster/main amd64 python3.7-minimal amd64 3.7.3-2+deb10u2
  404  Not Found [IP: 151.101.54.132 80]
E: Failed to fetch http://deb.debian.org/debian/pool/main/p/python3.7/python3.7-minimal_3.7.3-2+deb10u2_amd64.deb  404  Not Found [IP: 151.101.54.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

I tried to use --fix-missing but it didn’t work for me

Give us a bit more context please.
Are we talking about Streamlit sharing?
If yes, please provide a link to your public github repo.
I am guessing you are using the librosa library?

Hi @Maria :grinning_face_with_smiling_eyes:

I see the error on the main page of the Speech Emotion Recognition app you’ve previously shared :mag:

Could you first try replacing libsndfile-dev in line 5 of packages.txt with libsndfile1 ? If that doesn’t work, try replacing it with libsndfile1-dev and let us know if it helps :crossed_fingers:

Happy Streamlit-ing! :balloon:
Snehan

1 Like

@Maria

This will do the job in your packages.txt file:

libsndfile1-dev
1 Like

Hi @snehankekre! Thanks for the answer, but it doesn’t work for me either. I replaced libsndfile-dev with libsndfile1-dev and then with libsndfile1 and even tried to install both of them, but the error remained.

Thanks for getting back to me, @Maria :balloon:

I was able to fork your repo and successfully deploy to Streamlit Sharing after adding libsndfile1-dev to packages.txt. The contents of the file are exactly the following:

python3.7-venv
freeglut3-dev
libgtk2.0-dev
libasound2-dev
libsndfile1-dev
ffmpeg

Could try making the :point_up: change and re-booting your app?

The app should look like this once you reboot it:

Happy Streamlit-ing! :balloon:
Snehan

It was really helpful. I just deleted the app and reinstalled it from the repo and everything works! Many thanks.
Have a nice day! :slightly_smiling_face:

1 Like

Yay!! :tada: Happy to help :partying_face:

1 Like

I doubt that most of these packages are even needed. :wink:

@Maria

I also noticed that your requirements.txt is bloated with lots of packages that I don’t think are needed. This can also lead to unwanted problems during deployment.

1 Like

@Maria

I cloned your repository and cleaned it up a bit.
I tested it locally in a docker container and also on streamlit sharing.
Find the repo here:

The only required packages in packages.txt seems to be:

libsndfile1-dev
2 Likes

Hi @Franky1!
Wow, thank you very much for your help :relaxed: :pray:
I definitely need to learn more about deployment. Could you recommend some tools for me to determine which libraries I need for a project and which ones are unnecessary?

Regarding the python pip libraries, this is relatively simple.
All imports that do not belong to the Python standard library and that you use in your python program with import must be entered in the requirements.txt file.

There is also a python tool called pipreqs that scans the python scripts for non-standard import modules and writes them to a requirements.txt file.

But be careful: Sometimes the import modules are named differently than the package name you want to install.
For example: import cv2 versus pip install opencv-python-headless


There is no quick answer for the dependencies to be entered in packages.txt. To my knowledge, there is no tool for that either. Most python pip packages do not need additional apt install packages.
If they do, only helps: I look in the documentation of the python libraries, usually there is described which external libraries are required as prerequisites.

For corresponding error messages you can also google, but not everything you find e.g. on stackoverflow is correct and up to date. A lot of information is outdated.


Also, I usually test my streamlit app locally first in a Docker container, which is very similar to the streamlit sharing runtime. If there are no error messages anymore and the streamlit app works, the deployment to streamlit sharing usually works as well.
You can also find the corresponding Docker files in my cloned github repo.

Hey @snehankekre @Franky1, I’am facing the same problem.
I have used librosa and its showing me OSError: sndfile library not found.

Then I tried using,
freeglut3-dev
libgtk2.0-dev
libasound2-dev
libsndfile1-dev
ffmpeg

in my requirements.txt
But it’s not working for me. I have attached the ss of error.

Can you please help?
My public repo- GitHub - Rushanksavant/Tool-Sound-Classifier

Hi @Rushank_Savant, happy to help :slightly_smiling_face:

  1. Remove the following from your requirements.txt:

    freeglut3-dev
    libgtk2.0-dev
    libasound2-dev
    libsndfile1-dev
    ffmpeg
    
  2. :point_up: Those are not Python packages and should not be included in your requirements. They are apt-get dependencies and belong in their own packages.txt file. However, for librosa, only libsndfile1-dev is required in packages.txt.

  3. Create a new packages.txt file containing only:

    libsndfile1-dev
    

Once you’ve removed those entries from your requirements and have created the packages.txt file, your app should successfully deploy on Streamlit Sharing :tada: :partying_face:

Happy Streamlit-ing! :balloon:
Snehan

2 Likes

Hey @snehankekre, it worked :star_struck:
Thanks a lot.

2 Likes

Hi Even I am facing the same issue
while Deploying model in GCP through streamlit i am getting the error as “OSError: sndfile library not found”
Capture

Project deployed link : Project
Github Link : Speech Recognition Github

@snehankekre Please help.

Hi @Sandeep_R,

The instructions in this thread are specific to deployments on Streamlit sharing. Deployments on App Engine won’t install apt-get dependencies from your packages.txt file.

Have you tried including your apt-get dependencies in your Dockerfile? For example, after you pip install your Python dependencies:

RUN apt-get update && apt-get install -y libsndfile1-dev

Best, :balloon:
Snehan

1 Like

Hi, @snehankekre thank you very much for the input. I made the changes and now the Web app if working fine without any errors. :grinning: .

1 Like

Good job @snehankekre !!!

I also ran into the error of OSError: sndfile library not found when i tried to do import librosa. I tried tactics mentioned above:

  • Create packages.txt that contains libsndfile1-dev
  • Create requirement.txt with librosa - that’s similar to the public repos above.
  • Reboot the app, delete and create a new app.

Yet still got the same error. May I ask for some help from the community?
The repo is https://github.com/bojne/capstone-dev/app and the file that has error is app.py.

Thank you a ton!

Yeuh Han

I resolved this issue by putting the packages.txt at the root directory. This was an issue when I put the packages.txt at a sub folder of the repo. Hope this helps someone!