无法运行 .py 文件 | AttributeError:模块“集合”没有属性“MutableSequence”

R-K*_*R-K 2 python traceback pyxb

我正在使用 odx 文件,并且有一个要运行的generate.py 文件。我正在使用 pyXB。当我尝试跑步时,我得到了这个。

*回溯(最近一次调用最后一次):
文件“C:\Users\rohitkr\Downloads\starter_kit_adas-master\starter_kit_adas-master\devops\scripts\generate_odxf\generate_odxf.py”,第 15 行,来自
schema import odx

文件“C:\Users\rohitkr\Downloads\starter_kit_adas-master\starter_kit_adas-master\devops\scripts\generate_odxf\schema\odx.py”,第 9 行,导入 pyxb.binding

文件“C:\Users\rohitkr\AppData\Local\Programs\Python\Python310\lib\site-packages\pyxb\binding_ init _.py”,第 8 行,来自 . 导入数据类型

文件“C:\Users\rohitkr\AppData\Local\Programs\Python\Python310\lib\site-packages\pyxb\binding\datatypes.py”,第 1266 行,位于 rom 中。导入内容

文件“C:\ Users \ rohitkr \ AppData \ Local \ Programs \ Python \ Python310 \ lib \ site-packages \ pyxb \ binding \ content.py”,第807行,在类_PluralBinding(collections.MutableSequence)中:

AttributeError:模块“集合”没有属性“MutableSequence”*“”

可能是什么问题呢?提前致谢。

jup*_*bjy 10

在 python 3.10 中,MutableSequence 被删除collections以支持collections.abc

自版本 3.3 起已弃用,将在版本 3.10 中删除:将集合抽象基类移至 collections.abc 模块。为了向后兼容,它们在 Python 3.9 中继续在此模块中可见。

>>> from collections import MutableSequence
Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
ImportError: cannot import name 'MutableSequence' from 'collections' (C:\Program Files\Python310\lib\collections\__init__.py)

>>> from collections.abc import MutableSequence

Run Code Online (Sandbox Code Playgroud)


Saw*_*aha 6

如果您不想更改源代码,还有一种更简单的方法。导入后只需在脚本中使用它即可。

import collections
collections.MutableSequence = collections.abc.MutableSequence
Run Code Online (Sandbox Code Playgroud)