You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

深度学习语音活动检测训练报错:'CacheManager'无'cachedir'属性

问题解决:AttributeError: 'CacheManager' object has no attribute 'cachedir'

我在基于深度学习开展语音活动检测工作时,运行Python脚本train.py出现如下错误:

AttributeError: 'CacheManager' object has no attribute 'cachedir'

已尝试搜索相关解决方案但未找到有效结果,报错代码来自\site-packages\librosa\cache.py,具体代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Function caching"""

import os
import sys
from joblib import Memory


class CacheManager(Memory):
    '''The librosa cache manager class extends joblib.Memory
    with a __call__ attribute, so that it may act as a function.

    This allows us to override the librosa.cache module's __call__
    field, thereby allowing librosa.cache to act as a decorator function.
    '''

    def __init__(self, cachedir, level=10, **kwargs):
        super(CacheManager, self).__init__(cachedir, **kwargs)
        # The level parameter controls which data we cache
        # smaller numbers mean less caching
        self.level = level

    def __call__(self, level):
        '''Example usage:

        @cache(level=2)
        def semi_important_function(some_arguments):
            ...
        '''
        def wrapper(function):
            '''Decorator function.  Adds an input/output cache to
            the specified function.'''

            from decorator import FunctionMaker

            def decorator_apply(dec, func):
                """Decorate a function by preserving the signature even if dec
                is not a signature-preserving decorator.

                This recipe is derived from
                http://micheles.googlecode.com/hg/decorator/documentation.html#id14
                """

                return FunctionMaker.create(
                    func, 'return decorated(%(signature)s)',
                    dict(decorated=dec(func)), __wrapped__=func)

            if self.cachedir is not None and self.level >= level:
                return decorator_apply(self.cache, function)

            else:
                return function
        return wrapper


# Instantiate the cache from the environment
CACHE = CacheManager(os.environ.get('LIBROSA_CACHE_DIR', None),
                     mmap_mode=os.environ.get('LIBROSA_CACHE_MMAP', None),
                     compress=os.environ.get('LIBROSA_CACHE_COMPRESS', False),
                     verbose=int(os.environ.get('LIBROSA_CACHE_VERBOSE', 0)),
                     level=int(os.environ.get('LIBROSA_CACHE_LEVEL', 10)))

# Override the module's __call__ attribute
sys.modules[__name__] = CACHE

报错发生在第49行:if self.cachedir is not None and self.level >= level:


问题原因

这个错误是由于joblib版本兼容性问题导致的:joblib的Memory类在新版本中将属性cachedir改名为location,但当前使用的librosa版本仍在引用旧属性名self.cachedir,因此触发属性找不到的错误。

解决方案

提供三种可行的解决办法,任选其一即可:

  1. 降级joblib到兼容版本
    执行以下命令安装与当前librosa版本兼容的joblib版本:

    pip install joblib==0.16.0
    
  2. 修改librosa的cache.py代码
    找到site-packages/librosa/cache.py文件,将第49行的self.cachedir替换为self.location,修改后该行代码变为:

    if self.location is not None and self.level >= level:
    
  3. 升级librosa到最新版本
    新版本的librosa已经修复了这个兼容性问题,执行升级命令:

    pip install --upgrade librosa
    

内容的提问来源于stack exchange,提问作者Aisyah Robi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 19:32:11