简体   繁体   English

使用 VSCode 和 Pycharm 运行 python 代码时 GUI 不出现

[英]GUI does not appear when running python code with VSCode and Pycharm

I was trying to write some python code, inside my code I imported the turtle module and when I ran my code on VSCode I expected to see a GUI window but instead I got the following errors:我试图编写一些 python 代码,在我的代码中我导入了海龟模块,当我在 VSCode 上运行我的代码时,我希望看到一个 GUI window 但我得到了以下错误:

在此处输入图像描述

And besides that I get a Problem Report for Python showing up:除此之外,我还收到了 Python 的问题报告:

在此处输入图像描述

This is what my code looks like:这就是我的代码的样子:

import turtle

my_turtle = turtle.Turtle()

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

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

My macOS version is 11.1 btw.我的 macOS 版本是 11.1 顺便说一句。

Correct me if I'm wrong but apparently Python 2.7.16 does not support the Turtle module, so I switched my python version to 3.9.1 on the terminal and when I ran python main.py the GUI finally appeared.如果我错了,请纠正我,但显然 Python 2.7.16 不支持 Turtle 模块,所以我在终端上将 python 版本切换到 3.9.1,当我运行python main.py时终于出现了。

I used the following command to switch python versions on my terminal:我使用以下命令在终端上切换 python 版本:

alias python="python3"

Although I have solved this problem on my terminal, I have yet to see a way to change the python version on VSCode.虽然我已经在我的终端上解决了这个问题,但我还没有看到在 VSCode 上更改 python 版本的方法。

Perhaps you should install python 3.9.1 directly into your machine, so you don't worry about it.也许您应该将 python 3.9.1 直接安装到您的机器中,这样您就不用担心了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM