python - 如何解决包中的非类型错误 (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 UnicodeError
为except (UnicodeError, AttributeError)
. 对于剩余的错误,我需要使用命令强制将某些变量解释为字符串str()
。我仍然不确定采用这种蛮力方法是否会产生无法预料的后果,所以我没有将其标记为答案。
解决方案
推荐阅读
- r - 如何过滤数据框中不在另一行中事件值的特定时间范围内的行?
- android - 无法使用 ARCore SDK 编译 Unity 项目 - Gradle 出现问题
- java - 无法从 SQLite 表中显示 ListView 元素
- javascript - 使用 pm2 在后台执行节点应用程序作为服务(无路由)
- java - Mockito any vs any(MyClass.class)
- python - 熊猫如何在数据框列中提取整数和浮点数的混合
- python - 如何将输入从表单链接到变量 PyQt5 的问题
- python - 保存到csv时如何从多索引熊猫数据框中删除重复值
- vega-lite - 我可以让它看起来更像一个箱形图吗
- c++ - 如果中间有线程连接,为什么不能使用宽松的原子操作来同步内存?