首页 > 解决方案 > 如何解决包中的非类型错误 (ecco_v4_py)

问题描述

我最近在更新到 Mac OS Big Sur 后不得不重新创建一个环境,并且遇到了 Spyder 无法打开的常见问题。该环境的一个关键组件是处理 ECCO 状态估计数据所必需的 ecco_v4_py 包。

我设法将软件包安装到环境中,但是每当我尝试将其加载时,import ecco_v4_py as ecco都会出现以下错误。

 File "/Users/drew/anaconda3/envs/Salt/lib/python3.9/inspect.py", line 632, in cleandoc
    lines = doc.expandtabs().split('\n')

AttributeError: 'NoneType' object has no attribute 'expandtabs' 

我尝试使用 ecco_v4_py 和 Spyder 创建一个全新的环境,但这会产生相同的错误。我还尝试使用降级版本的软件包创建一个全新的环境,但这也会导致此错误。

更深入地研究这个问题,我转到库代码中引发错误的行。

def cleandoc(doc):
    """Clean up indentation from docstrings.

    Any whitespace that can be uniformly removed from the second line
    onwards is removed."""
    try:
        lines = doc.expandtabs().split('\n') #This is the line that is failing
    except UnicodeError:
        return None
    else:
        # Find minimum indentation of any non-blank lines after first line.
        margin = sys.maxsize
        for line in lines[1:]:
            content = len(line.lstrip())
            if content:
                indent = len(line) - content
                margin = min(margin, indent)
        # Remove indentation.
        if lines:
            lines[0] = lines[0].lstrip()
        if margin < sys.maxsize:
            for i in range(1, len(lines)): lines[i] = lines[i][margin:]
        # Remove any trailing or leading blank lines.
        while lines and not lines[-1]:
            lines.pop()
        while lines and not lines[0]:
            lines.pop(0)
        return '\n'.join(lines)

但是当我只运行这个块时它可以工作,所以我不确定为什么当我尝试导入包时它会抛出错误。

小编辑:我也尝试安装早期版本的 python,但这并不能解决问题。我尝试编辑引发错误的文件以解决问题,但进一步的错误出现在该行。

附加编辑:我设法让 ecco_v4_py 包正常工作,方法是手动进入并在出现错误时编辑文件。对我来说,它需要更改except UnicodeErrorexcept (UnicodeError, AttributeError). 对于剩余的错误,我需要使用命令强制将某些变量解释为字符串str()。我仍然不确定采用这种蛮力方法是否会产生无法预料的后果,所以我没有将其标记为答案。

标签: pythonspyder

解决方案


推荐阅读