python-soundfile
python-soundfile copied to clipboard
Unable to import soundfile
Unable to import soundfile and I'm presented with the below error message.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\anaconda3\lib\site-packages\soundfile.py in <module>
161 import _soundfile_data # ImportError if this doesn't exist
--> 162 _path = _os.path.dirname(_soundfile_data.__file__) # TypeError if __file__ is None
163 _full_path = _os.path.join(_path, _packaged_libname)
~\anaconda3\lib\ntpath.py in dirname(p)
220 """Returns the directory component of a pathname"""
--> 221 return split(p)[0]
222
~\anaconda3\lib\ntpath.py in split(p)
182 Either part may be empty."""
--> 183 p = os.fspath(p)
184 seps = _get_bothseps(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
~\anaconda3\lib\site-packages\soundfile.py in <module>
170 raise OSError('sndfile library not found using ctypes.util.find_library')
--> 171 _snd = _ffi.dlopen(_libname)
172
OSError: cannot load library 'C:\Users\danie\anaconda3\Library\bin\sndfile.dll': error 0x7e
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-5-bb1f00ee4bd6> in <module>
----> 1 import soundfile as sf
2
~\anaconda3\lib\site-packages\soundfile.py in <module>
190 _snd = _ffi.dlopen(_os.path.join(_hbrew_path, _explicit_libname))
191 else:
--> 192 _snd = _ffi.dlopen(_explicit_libname)
193
194 __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')
OSError: cannot load library 'libsndfile.dll': error 0x7e
I'm using python 3.7.16 and installed soundfile-0.12.1 using pip install soundfile
Just to add for additional information - I got the above when trying to use soundfile within my base conda environment. When I create a fresh environment it seems to work fine.
This error clearly originates from anaconda. Something about the libsndile.dll they ship is incompatible with your version of Python. Try updating your pip, possibly update your wheel (pip install --upgrade pip wheel), and then reinstall soundfile. This should give you the binary wheels I publish on Pypi, which should contain compatible versions of libsndfile.