2

I get an error when I try import soundfile.

I tried reinstalling soundfile via pip, but didn't work.

Here's the error I get.

Traceback (most recent call last):
  File "/Users/kona/.pyenv/versions/3.9.5/lib/python3.9/site-packages/soundfile.py", line 142, in <module>
    raise OSError('sndfile library not found')
OSError: sndfile library not found

During handling of the above exception, another exception occured:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/kona/.pyenv/versions/3.9.5/lib/python3.9/site-packages/soundfile.py", line 162, in <module>
        _snd = _ffi.dlopen(_os.path.join(
    OSError: cannot load library '/Users/kona/.pyenv/versions/3.9.5/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/Users/kona/.pyenv/versions/3.9.5/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib, 2): image not found

When I did mdfind _soundfile_data and mdfind libsndfile.dylib, it gave me no results. Also, when I did brew install libsndfile, it told me it was already installed and up-to-date.

Marlon Richert
  • 5,250
  • 1
  • 18
  • 27
salfare
  • 31
  • 2
  • Did you install via pip after activating the venv for python or outside of the venv? (I presume seeing your `.pyenv` you are using some virtualenv) – Nagaraj Tantri Jun 16 '21 at 05:55
  • @NagarajTantri Pyenv doesn't manage virtualenvs. It lets you manage multiple Python installations on the same machine: https://github.com/pyenv/pyenv – Marlon Richert Jun 16 '21 at 08:12
  • @MarlonRichert thanks, by the looks of it, I thought it was a virtualenv. Didn't know the existence of this tool. – Nagaraj Tantri Jun 16 '21 at 12:58

1 Answers1

0

Workaround is here: https://github.com/ohmtech-rdi/eurorack-blocks/issues/444#issuecomment-1153155080

% brew install libsndfile
...
% brew list libsndfile
...
/opt/homebrew/Cellar/libsndfile/1.1.0/lib/libsndfile.1.dylib
/opt/homebrew/Cellar/libsndfile/1.1.0/lib/libsndfile.dylib
% ls -l /opt/homebrew/Cellar/libsndfile/1.1.0/lib/
total 912
-r--r--r--  1 raf  admin  466656 Jun 12 14:42 libsndfile.1.dylib
lrwxr-xr-x  1 raf  admin      18 Mar 27 14:42 libsndfile.dylib -> libsndfile.1.dylib
drwxr-xr-x  3 raf  admin      96 Jun 12 14:42 pkgconfig
% mkdir -p /opt/homebrew/lib/python3.9/site-packages/_soundfile_data
% cp /opt/homebrew/Cellar/libsndfile/1.1.0/lib/libsndfile.1.dylib /opt/homebrew/lib/python3.9/site-packages/_soundfile_data/

This should get fixed soon. See discussion here: https://github.com/bastibe/python-soundfile/issues/310

Another workaround:

brew install libsndfile
DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH" python my_file.py
UFO
  • 131
  • 1
  • 4