gpt4 book ai didi

python - "from __future__ import annotations"在 VSCode 中产生 "annotations is not defined"

转载 作者:行者123 更新时间:2023-11-28 18:03:04 25 4
gpt4 key购买 nike

    from __future__ import annotations
SyntaxError: future feature annotations is not defined

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

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

最佳答案

除非你创建了一个虚拟环境并选择它作为你的解释器,否则输入类似 python3 myfile.py 的东西将不能保证你使用的是你在 VS Code 中选择的 Python 解释器(它在你的 shell,而不是 VS Code)。确保使用在终端中运行 Python 文件,因为这将确保您的文件使用选定的 Python 解释器运行。

关于python - "from __future__ import annotations"在 VSCode 中产生 "annotations is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54993232/

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