eurorack-blocks
eurorack-blocks copied to clipboard
Python3 soundfile doesn't work on macOS/M1
Python3 soundfile doesn't work on macOS M1.
Steps to reproduce
% pip3 install sound file
...
% pip3 list | grep SoundFile
SoundFile 0.10.3.post1
% python3
Python 3.9.13 (main, May 24 2022, 21:13:51)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import soundfile
Traceback (most recent call last):
File "/opt/homebrew/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 occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/lib/python3.9/site-packages/soundfile.py", line 162, in <module>
_snd = _ffi.dlopen(_os.path.join(
OSError: cannot load library '/opt/homebrew/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/opt/homebrew/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib, 0x0002): tried: '/opt/homebrew/lib/python3.9/site-packages/_soundfile_data/libsndfile.dylib' (no such file)
There is no _soundfile_data in the site-packages/ folder.
However the SoundFile project is working on a new 0.11 release to address this problem, which details are captured in this issue.
The 0.11 release is still pre-release, with b5 just 9 days ago (relative to the time of this post).
Workarounds
Fix
It is not the first time that our dependencies fails to install. We are only using a very small part of libsndfile, as we officially only support the wav format. Furthermore SoundFile doesn't support all functions of the library, and we need to access the cue markers later in the project.
So one way to solve this would be to make our WAV parser directly in Python to remove this dependency.
Workaround shell session for reference:
% 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/
% python3
Python 3.9.13 (main, May 24 2022, 21:13:51)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import soundfile
>>>
SoundFile 0.12.1 version of libsndfile now supports M1 Mac, but relies on pip at least version 22.2 because wheel universal2 tag appeared in 22.2, and SoundFile relies on it to install binary packages.