如何摆脱 Visual studio 代码终端中打印的不必要路径?

How can I get rid of unnecessary paths being printed in Visual studio Code Terminal?

每次我在 VScode 中 运行 我的 python 脚本时,我都会在终端中打印以下行:

Microsoft Windows [Version 10.0.19041.630]
(c) 2020 Microsoft Corporation. All rights reserved.

E:\My Laptop\Coding\Python\Study files\Projects>C:/ProgramData/Anaconda3/Scripts/activate

(base) E:\My Laptop\Coding\Python\Study files\Projects>conda activate base

(base) E:\My Laptop\Coding\Python\Study files\Projects>C:/ProgramData/Anaconda3/python.exe "e:/My Laptop/Coding/Python/Study files/Projects/100_Clean.py"

比程序正常执行。执行结束时,我得到这一行:

(base) E:\My Laptop\Coding\Python\Study files\Projects>

为什么要打印这些行?如何在 VSCode 设置中关闭它们?

(base) E:\My Laptop\Coding\Python\Study files\Projects> 不是来自您的程序,它是在命令提示符(在 VS 代码中)中键入命令的区域。

据我所知,没有办法隐藏路径,因为 VS Code 集成终端基本上使用的是 OS/system 的底层终端。 运行 Python 终端上的脚本通常需要您指定路径。

一种解决方法是在同一终端 window 中 运行 您的代码之前使用“提示”命令。 像这样:

prompt $$

另一种解决方法是按照其他人的建议使用调试控制台。

最方便的方法是像这样编辑您的用户settings.json

"terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/K", "prompt $G"],

现在我的集成终端看起来像这样

>C:/Users/guido/miniconda3/Scripts/activate
(base) >conda activate condavenv
(condavenv) >

或者,您可以在市场上寻找 Code Runner 扩展 - 它可以选择完全按照您的要求执行操作:仅打印代码的输出,不打印任何其他内容 .

上述工作解决方案之一似乎已被弃用;您可以为 "terminal.integrated.profiles.windows":

调整 vscode 设置

示例:

 "Command Prompt": {
       "path": ["C:\WINDOWS\System32\cmd.exe"],
       "args": ["/K", "prompt $G$S "],  }