“从 __future__ 导入注释”导致 VSCode 中的“注释未定义”

Bem*_*huo 5 python import python-3.x visual-studio-code

    from __future__ import annotations
SyntaxError: future feature annotations is not defined
Run Code Online (Sandbox Code Playgroud)

当我尝试在 VSCode 终端中运行我的代码时出现此错误。当我用 PyCharm 运行我的代码时,我从来没有出现过这个错误。我只是不明白是什么让它在 VSCode 中不起作用。

我使用 Python 3.7 作为我的项目解释器。

Bre*_*non 3

除非您创建了一个虚拟环境并选择它作为您的解释器,否则键入类似内容并python3 myfile.py不能保证您正在使用您在 VS Code 中选择的 Python 解释器(该解释器由您的 shell 控制,而不是 VS Code)。请务必使用Run Python File in Terminal,因为这将确保您的文件使用所选的 Python 解释器运行。