OSError: sndfile library not found

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!

Hey snehankekre!

I have followed your instructions but my streamlit app has an error installing dependencies!
I ahve tried rebooting it a couple of times to no avail.

Can you help me out please?
This is the app - https://share.streamlit.io/soft-nougat/dqw-ivves/app.py
This is the repo - GitHub - soft-nougat/dqw-ivves: DQW is an EDA tool for training data.

Thanks!
Tia

Fixed it! :slight_smile:

All it needed is deleting! I deleted the app and redeployed it - works fine.

Happy holidays! :christmas_tree:

1 Like

ERROR: No matching distribution found for libsndfile1-dev
WARNING: You are using pip version 22.0.3; however, version 22.3.1 is available.
You should consider upgrading via the ‘/home/appuser/venv/bin/python -m pip install --upgrade pip’ command.

raise OSError(‘sndfile library not found’)

I faced the same issue. sndfiIe not found. tried to use above solutions. I used libsndfile1-dev as per the solutions. but now its gave “No matching distribution found for libsndfile1-dev” error. Please help me.

mmtdmackonal/spoofed-audio-detector (github.com)

https://mmtdmackonal-spoofed-audio-detector-main-ce5rkb.streamlit.app/

Reequipments file include:
streamlit
numpy
tensorflow
pandas
matplotlib
opencv-python
wave
opencv-python
soundfile

Thank you.

1 Like

@TM_Daminda welcome to the Streamlit forum! :balloon:

Please read our guidelines on how to post an effective question to the forum, and edit your original post to include all of the following:

Links to your app, GitHub repo, and the contents of your requirements file + packages.txt

@snehankekre Thank you very much for the instructions.

You have entries in your requirements.txt that are not Python packages…

The solution above was to create a packages.txt containing:

libsndfile1-dev

If you keep those non-Python-packages in your requirements file, you are bound to run into more errors.

Thank you sir. now getting error with importing cv2 .