25

while using import soundfile on wither python3 or python I am getting:

Traceback (most recent call last): File "", line 1, in File "/home/erezsh/.local/lib/python3.6/site-packages/soundfile.py", line 142, in raise OSError('sndfile library not found') OSError: sndfile library not found

I found this post which did not help because I am using soundfile and not pysoundfile and the link it offers is broken.

Also, here I could not find a solution since I have installed using pip install SoundFile.

I am using Ubuntu shell on windows. Is this of any importance?

How do I solve this?

5 Answers 5

53

You need to install the needed library:

On Linux, you need to install libsndfile using your distribution’s package manager, for example sudo apt-get install libsndfile1.

From PyPI

1
  • This answer helped me run my code in a Linux based docker when my PC is Windows. Thank you. Aug 11, 2020 at 16:46
17

handras answer (from 2019) is not working now (in 2020) so install libsndfile1 via ( as A.B.)

sudo apt-get install libsndfile1-dev
4
  • @havakok Have you noticed "-dev" ? handras answer gives different name of the package.
    – Adam
    Jun 13, 2020 at 19:21
  • No, though I don't see why is it adding on the existing answers?
    – havakok
    Jun 14, 2020 at 5:53
  • @havakok. Because handras answer from 2019 is now working in 2020
    – Adam
    Jun 14, 2020 at 6:47
  • Can you add that to your answer so I can change the vote (locked now)?
    – havakok
    Jun 15, 2020 at 7:17
7

Try using the conda installation is you do not have sudo priviliges.

It worked for me, while I continued to face issues via the pip installation.

conda install -c conda-forge librosa

The above command installs librosa. You might be able to find a specific one for only soundfile too.

3

UPDATE: Needed to run apt update first, and it worked.

The accepted answer at first did not work for me.

I'm inside a docker image:

apt-get install libsndfile1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package libsndfile1
1
  • Running apt update was the solution for me in the Deepnote terminal too
    – mre
    May 17, 2021 at 15:04
2

in case of yum package manager users first install the dependency

 sudo yum -y install libsndfile

afterwards run the pip installs

pip install SoundFile
pip install librosa

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.