解决import librosa报错cannot load library soundfile-0.10.3.post1-py3.7.egg\_soundfile_data\libsndfile...

In [2]: import librosa
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\soundfile-0.10.3.post1-py3.7.egg\soundfile.py in <module>
    141     if _libname is None:
--> 142         raise OSError('sndfile library not found')
    143     _snd = _ffi.dlopen(_libname)

OSError: sndfile library not found

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-2-989066361697> in <module>
----> 1 import librosa

c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\librosa\__init__.py in <module>
     10 # And all the librosa sub-modules
     11 from ._cache import cache
---> 12 from . import core
     13 from . import beat
     14 from . import decompose

c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\librosa\core\__init__.py in <module>
    124
    125 from .time_frequency import *  # pylint: disable=wildcard-import
--> 126 from .audio import *  # pylint: disable=wildcard-import
    127 from .spectrum import *  # pylint: disable=wildcard-import
    128 from .pitch import *  # pylint: disable=wildcard-import

c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\librosa\core\audio.py in <module>
      8 import warnings
      9
---> 10 import soundfile as sf
     11 import audioread
     12 import numpy as np

c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\soundfile-0.10.3.post1-py3.7.egg\soundfile.py in <module>
    161
    162     _snd = _ffi.dlopen(_os.path.join(
--> 163         _path, '_soundfile_data', _libname))
    164
    165 __libsndfile_version__ = _ffi.string(_snd.sf_version_string()).decode('utf-8', 'replace')

OSError: cannot load library 'c:\users\zlyx1\.conda\envs\tf2_3_gpu\lib\site-packages\soundfile-0.10.3.post1-py3.7.egg\_soundfile_data\libsndfile64bit.dll': error 0x7e

在import librosa时提示此类错误。通过排查发现,在soundfile-0.10.3.post1-py3.7.egg文件夹下没有_soundfile_data文件夹,自然也就没有libsndfile64bit.dll文件。

  • 解决方法:
    (1) 首先在soundfile-0.10.3.post1-py3.7.egg文件夹下创建一个文件名为_soundfile_data的文件夹
    (2)下载libsndfile64bit.dll文件。推荐一个下载的网址:bastibe/libsndfile-binaries: Pre-compiled shared libraries for libsndfile (github.com),根据自己的电脑配置选择32位或者64位的
    (3)将下载的libsndfile64bit.dll文件移到_soundfile_data文件夹下面就ok了。
    测试一下:
    此时可以正常导入了。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容