ImportError: cannot import name 'Parser'

ImportError: cannot import name 'Parser'

我有一堆模块。下面列出了模块及其导入:

ast.py:
    import enum
    from abc import ABC, abstractmethod
err.py:
    none
lexer.py:
    from token import TokenTag, Token
parser.py:
    from ast import *
    from err import UndeclaredIdentError, SyntaxError
    from token import TokenTag as Tag
    from type import Type
peep.py:
    from lexer import Lexer
    from parser import Parser
token.py:
    import enum
treewalker.py:
    from abc import ABC, abstractmethod
type.py:
    import enum
    from treewalker import TreeWalker

我尝试 运行 peep.py 但出现以下错误:

Traceback (most recent call last):
  File "peep.py", line 2, in <module>
    from parser import Parser
ImportError: cannot import name 'Parser'

我不明白为什么会出现 ImportError,我在上面的文件层次结构中找不到任何明显的循环依赖项。我做了一些研究,我认为我应该将模块 ast.py 重命名为 syntaxtree.py 因为 ast.py 已经存在于 Python 的标准库中。重命名后,它产生了相同的结果。感谢任何形式的帮助,谢谢!

打开 parser.py 文件并将 from parser import Parser 的代码更改为 from .parser import Parser