librosa: conda librosa 0.8.0: cffi library Attribute Error using librosa.load() for .wav file

I installed librosa 0.8.0 into a conda environment having Python 3.8.6 and conda 4.9.1:

> conda install librosa
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\me\Miniconda3\envs\forge38

  added / updated specs:
    - librosa


The following NEW packages will be INSTALLED:

  appdirs            pkgs/main/noarch::appdirs-1.4.4-py_0
  audioread          conda-forge/win-64::audioread-2.1.8-py38h32f6830_3
  libflac            conda-forge/win-64::libflac-1.3.3-h6538335_0
  libogg             pkgs/main/win-64::libogg-1.3.2-he774522_0
  librosa            conda-forge/noarch::librosa-0.8.0-pyh9f0ad1d_0
  libsndfile         conda-forge/win-64::libsndfile-1.0.29-ha925a31_0
  libvorbis          pkgs/main/win-64::libvorbis-1.3.7-he774522_0
  llvmlite           pkgs/main/win-64::llvmlite-0.34.0-py38h1a82afc_4
  numba              pkgs/main/win-64::numba-0.51.2-py38hf9181ef_1
  pooch              conda-forge/noarch::pooch-1.2.0-py_0
  pysoundfile        conda-forge/noarch::pysoundfile-0.10.2-py_1001
  resampy            conda-forge/noarch::resampy-0.2.2-py_0

Output of librosa.show_versions():

INSTALLED VERSIONS
------------------
python: 3.8.6 | packaged by conda-forge | (default, Oct  7 2020, 18:22:52) [MSC v.1916 64 bit (AMD64)]

librosa: 0.8.0

audioread: 2.1.8
numpy: 1.19.2
scipy: 1.5.0
sklearn: 0.23.2
joblib: 0.17.0
decorator: 4.4.2
soundfile: 0.10.2
resampy: 0.2.2
numba: 0.51.2

numpydoc: 1.1.0
sphinx: 3.3.0
sphinx_rtd_theme: None
sphinxcontrib.versioning: None
sphinx-gallery: None
pytest: None
pytest-mpl: None
pytest-cov: None
matplotlib: 3.3.2
presets: None

When I tried using librosa.load() on a .wav file, I get this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-33-070e4879b935> in <module>
      1 # Read in the first audio file, create the time array
----> 2 audio, sfreq = lr.load('Datasets/set_b/normal__278_1311163365896_A.wav')
      3 time = np.arange(0, len(audio)) / sfreq
      4 
      5 # Plot audio over time

~\Miniconda3\envs\forge38\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    144 
    145     try:
--> 146         with sf.SoundFile(path) as sf_desc:
    147             sr_native = sf_desc.samplerate
    148             if offset:

~\Miniconda3\envs\forge38\lib\site-packages\soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
    625         self._info = _create_info_struct(file, mode, samplerate, channels,
    626                                          format, subtype, endian)
--> 627         self._file = self._open(file, mode_int, closefd)
    628         if set(mode).issuperset('r+') and self.seekable():
    629             # Move write position to 0 (like in Python file objects)

~\Miniconda3\envs\forge38\lib\site-packages\soundfile.py in _open(self, file, mode_int, closefd)
   1168             if isinstance(file, _unicode):
   1169                 if _sys.platform == 'win32':
-> 1170                     openfunction = _snd.sf_wchar_open
   1171                 else:
   1172                     file = file.encode(_sys.getfilesystemencoding())

AttributeError: cffi library 'C:\Users\me\Miniconda3\envs\forge38\Library\bin\sndfile.dll' has no function, constant or global variable named 'sf_wchar_open'

Others have had this problem:

https://stackoverflow.com/questions/59915598/attributeerror-cffi-library-pymodulespath-soundfile-data-libsndfile64bit-dl

I then completely removed the conda librosa and replaced it with the version from pip, and the error went away, all is good.

> pip install librosa
...
Successfully built librosa audioread resampy
Installing collected packages: audioread, llvmlite, numba, resampy, soundfile, appdirs, pooch, librosa
Successfully installed appdirs-1.4.4 audioread-2.1.9 librosa-0.8.0 llvmlite-0.34.0 numba-0.51.2 pooch-1.2.0 resampy-0.2.2 soundfile-0.10.3.post1

However, I would much rather use the conda version. Please help me solve the problem with the conda version.

Thank you…

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (1 by maintainers)

Most upvoted comments

@pythonic2020

Interesting that libsndfile64bit.dll is nowhere in my py37 environment.

This would only be there if you installed the soundfile module with pip.

BTW, I just noticed something odd in the error message:

OSError: cannot load library '\Users\me\Miniconda3\envs\py37\Library\bin\sndfile.dll': error 0x7e

Seems like the drive letter C: is missing?

@wolfv

The libsndfile.dlp should be under $PREFIX/Library/bin/libsndfile.dll and not under site-packages.

Please note that there are two errors, the first trying conda’s DLL, the second one trying the bundled DLL from the wheel package (which isn’t available in the conda package).

First error:

OSError: cannot load library '\Users\me\Miniconda3\envs\py37\Library\bin\sndfile.dll': error 0x7e

Second error:

OSError: cannot load library 'C:\Users\me\Miniconda3\envs\py37\lib\site-packages\_soundfile_data\libsndfile64bit.dll': error 0x7e

The second error is expected and it wouldn’t happen if the DLL installed by conda would be found.

Maybe the problem is sndfile.dll vs. libsndfile.dll?