如何在 Windows 命令提示符中使用 Code Runner 在 Visual Studio Code 中运行 Python 脚本,同时在集成面板中显示错误?

发布于 01-15 04:16 字数 1173 浏览 3 评论 0原文

默认情况下,通过 VSCode Code Runner 运行 .py 文件会在 VSCode 集成终端中执行程序: 终端我希望它能够完全执行在集成终端中的操作,但通过单独的 Windows 命令提示符(如 PyCharm)启动代码。

如果我在 VSCode 中进入 settings.json,我可以将 "code-runner.runInTerminal": true, 更改为 false,它将执行output 选项卡中的代码而不是 terminal 选项卡中的代码。 输入图片此处描述这对我没有多大帮助。

settings.json 我可以更改:

在此处输入图像描述

至:

在此处输入图像描述

这会在我想要的外部终端中执行程序,但它有一些严重的缺点。首先,我每次都必须在代码末尾添加 input() ,以免它自动关闭。更大的问题是,如果我的代码中有某种逻辑错误,它不会向我显示任何类型的错误消息;只需关闭命令提示符即可。

有没有办法让代码在外部 Windows 命令提示符中执行,显示所有错误消息(在 VSCode 或终端本身中),并让终端需要输入即可关闭,而不需要 input()函数在我的代码末尾吗?

By default, running a .py file through VSCode Code Runner executes the program in the VSCode integrated terminal:
Terminal
I would like it to do exactly what it does in the integrated terminal, but launch the code through a separate Windows command prompt, like PyCharm.

If I go into settings.json in VSCode, I could change "code-runner.runInTerminal": true, to false, it will execute the code in the output tab instead of terminal tab.
enter image description here
This doesn't help me much.

From settings.json I can change:

enter image description here

to:

enter image description here

This executes the program in the external terminal I want, but it has some serious drawbacks. For one, I have to add input() at the end of my code every time in order for it not to automatically close. The bigger problem is that if I have some kind of logical error in my code, it won't show me any type of error message; just closes the command prompt.

Is there any way to have the code execute in an external Windows command prompt, show all error messages (either in VSCode or terminal itself), and have the terminal require input to close without needing the input() function at the end of my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

︶ ̄淡然2025-01-22 04:16:21

您可以从开始菜单打开 Windows 终端/命令提示符,导航到 python 文件并使用与 VSCode 中使用的相同的 python 命令运行 python 文件。

[在此处输入图像描述][1]

您无需将“input()”添加到代码中,并且您还将获得回溯。

编辑:重新上传图片。
[1]: https://i.sstatic.net/qzQz2.png

You can open windows terminal/command prompt from the start menu, navigate to your python file and use the same python command to run the python file that you used in VSCode.

[enter image description here][1]

You won't need to add "input()" to your code and you will also get tracebacks.

EDIT: reuploaded picture.
[1]: https://i.sstatic.net/qzQz2.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文