python-soundfile
python-soundfile copied to clipboard
libsndfile32bit.dll path
Hi, I was building a package with PyInstaller for a python script that calls PySoundFile functions. The DLLs are bundled into a 'dist' folder together with a Windows EXE of the program. However, when I ran the EXE, an error occurred in soundfile.py as it was looking for libsndfile32bit.dll in ...._soundfile_data folder though the DLL is already bundled into the same directory as the EXE.
When I looked into soundfile.py, the following section looks like the part that searches the DLL:
try:
_snd = _ffi.dlopen('sndfile')
except OSError as err:
if _sys.platform == 'darwin':
_libname = 'libsndfile.dylib'
elif _sys.platform == 'win32':
from platform import architecture as _architecture
_libname = 'libsndfile' + _architecture()[0] + '.dll'
else:
raise
_snd = _ffi.dlopen(_os.path.join(
_os.path.dirname(_os.path.abspath(__file__)),
'_soundfile_data', _libname))
Is there a better way to go about doing this as I would have to manually create "_soundfile_data" in the dist folder in order for the program to run correctly.
Thanks.
Just rename your dll to sndfile.dll, and it should work. See here for how dlopen searches for libraries.
The rationale is that PySoundFile first searches for any locally-installed sndfile (the first try). Only when this is not found, it searches for the PySoundFile-provided libsndfileXX.dll in _soundfile_data.
This will still fail at new versions, pyinstaller will fail to place the .dll correctly or even find it. Although your workaround fix the issue for now, it would be great if pyinstaller gets it automatically.
Hi there,
I don't know if I'm doing this wrong, but I have renamed libsndfile32bit.dll to sndfile.dll. All this is placed in the dist folder along with the exe, but it's still giving me the error. Am I supposed to place that file in a particular spot of python?
@tritipsteak IIRC, sndfile.dll is only found by ctypes/CFFI if you put it somewhere in the Windows PATH.
Did you try putting it in _soundfile_data\libsndfile32bit.dll (relative to the dist folder)?
There is this hack (see #192) which might work for this:
https://github.com/bastibe/SoundFile/blob/43c457e73984f15ca5c5ad47390dcc8e913da3c1/soundfile.py#L153-L163
do pip install pysoundfile