From 3b7c78574ce7493f4d697543a38cd3fafa53e658 Mon Sep 17 00:00:00 2001 From: PwnyTail Date: Sat, 27 Nov 2021 11:07:12 +0100 Subject: [PATCH 1/2] Try explicit file name, and look system-wide for library Try explicit file name, if the general does not work (e.g. on nixos) and if no local installed library sndfile, try system-wide --- soundfile.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/soundfile.py b/soundfile.py index 99c012c..f4a67fa 100644 --- a/soundfile.py +++ b/soundfile.py @@ -147,6 +147,9 @@ elif _sys.platform == 'win32': from platform import architecture as _architecture _libname = 'libsndfile' + _architecture()[0] + '.dll' + elif _sys.platform == 'linux': + # Try explicit file name, if the general does not work (e.g. on nixos) + _libname = 'libsndfile.so' else: raise @@ -159,8 +162,12 @@ while not _os.path.isdir(_path): _path = _os.path.abspath(_os.path.join(_path, '..')) - _snd = _ffi.dlopen(_os.path.join( - _path, '_soundfile_data', _libname)) + try: + _snd = _ffi.dlopen(_os.path.join( + _path, '_soundfile_data', _libname)) + except OSError: + # if no local installed library sndfile, try system-wide + _snd = _ffi.dlopen(_libname) __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace') if __libsndfile_version__.startswith('libsndfile-'): From afb883032815c794b1f97d2d7f9a7c1d86fad795 Mon Sep 17 00:00:00 2001 From: PwnyTail Date: Wed, 8 Dec 2021 14:45:40 +0100 Subject: [PATCH 2/2] solve merge conlict remove machine architecture for darwin. Lib directories not influenced by machine architecture. --- soundfile.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/soundfile.py b/soundfile.py index f4a67fa..8b2313a 100644 --- a/soundfile.py +++ b/soundfile.py @@ -167,7 +167,16 @@ _path, '_soundfile_data', _libname)) except OSError: # if no local installed library sndfile, try system-wide - _snd = _ffi.dlopen(_libname) + + # Homebrew on Apple M1 uses a `/opt/homebrew/lib` instead of + # `/usr/local/lib`. We are making sure we pick that up. + if _sys.platform == 'darwin': + _hbrew_path = '/opt/homebrew/lib/' if _os.path.isdir('/opt/homebrew/lib/') \ + else '/usr/local/lib/' + _snd = _ffi.dlopen(_os.path.join( + _hbrew_path, _libname)) + else: + _snd = _ffi.dlopen(_libname) __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace') if __libsndfile_version__.startswith('libsndfile-'):