无法导入声音文件(mac)



尝试import soundfile时出错。

我尝试通过pip重新安装声音文件,但没有成功。

这是我得到的错误。

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

当我做mdfind _soundfile_datamdfind libsndfile.dylib时,它没有给我任何结果。此外,当我做brew install libsndfile时,它告诉我它是already installed and up-to-date

解决方法如下: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/

这个问题应该很快就会解决。请参阅此处的讨论:https://github.com/bastibe/python-soundfile/issues/310

另一种解决方法:

brew install libsndfile
DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH" python my_file.py

最新更新