无法从未来导入批注__

2024-04-23 02:49:16 发布

您现在位置:Python中文网/ 问答频道 /正文

运行语句时

from __future__ import annotations

我得到以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.5/py_compile.py", line 125, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "./prog.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/py_compile.py", line 129, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 1
    from __future__ import annotations
                                     ^
SyntaxError: future feature annotations is not defined

这个错误的原因可能是什么?


Tags: infrompyimportmost错误linefuture
1条回答
网友
1楼 · 发布于 2024-04-23 02:49:16

看一下您的错误回溯,看起来您正在使用python 3.5。是这样吗?

如果是这样,则会发生错误,因为根据PEP-563,可以从Python 3.7开始导入__future__annotations

我没有发现任何提示,这将被移植到以前的版本,但我可能已经错过了。

相关问题 更多 >