Can't Import Soundfile Python

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

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

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

sudo apt-get install libsndfile1-dev
4

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.

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

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

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest