简体   繁体   中英

Cannot import soundfile (mac)

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM