【问题标题】:GUI does not appear when running python code with VSCode and Pycharm使用 VSCode 和 Pycharm 运行 python 代码时不出现 GUI
【发布时间】:2021-04-21 15:28:16
【问题描述】:

我试图编写一些 python 代码,在我的代码中我导入了 turtle 模块,当我在 VSCode 上运行我的代码时,我希望看到一个 GUI 窗口,但我得到了以下错误:

除此之外,我还收到了一份 Python 问题报告:

这是我的代码的样子:

import turtle

my_turtle = turtle.Turtle()

my_turtle.shape("turtle")
my_turtle.color("red")
my_turtle.forward(100)

screen = turtle.Screen()
screen.exitonclick()

我的 macOS 版本是 11.1 btw。

【问题讨论】:

  • 直接在终端运行是否有效?
  • 问题报告引用了 Python 2.7.16,该版本已过时且不再受支持。
  • “需要 macOS 11 或更高版本”出现在我的终端上
  • 如果它引用 Python 2.7.16 那么将 Python 更新到最新版本会有帮助吗?

标签: python macos visual-studio-code turtle-graphics


【解决方案1】:

如果我错了,请纠正我,但显然 Python 2.7.16 不支持 Turtle 模块,所以我在终端上将我的 python 版本切换为 3.9.1,当我运行 python main.py 时,GUI 终于出现了。

我使用以下命令在终端上切换 python 版本:

alias python="python3"

虽然我已经在终端上解决了这个问题,但我还没有看到在 VSCode 上更改 python 版本的方法。

【讨论】:

  • 你可能不应该有那个别名而自己直接使用python3。 vscode 知道如何引用正确的 Python 可执行文件
  • 我刚刚按照Irfan写的这篇博文中的步骤解决了这个问题。
【解决方案2】:

也许你应该直接在你的机器上安装python 3.9.1,这样你就不用担心了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-05
    • 2020-06-30
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多