gpt4 book ai didi

python - 无法从 __future__ 导入注释

转载 作者:太空狗 更新时间:2023-10-29 21:41:22 26 4
gpt4 key购买 nike

运行语句时

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

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

最佳答案

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

如果是这样,那么错误就会发生,因为根据 PEP-563 __future__ annotations 的导入从 Python 3.7 开始可用。

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

关于python - 无法从 __future__ 导入注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52889746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com