繁体   English   中英

如何摆脱在 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 设置中关闭它们?

据我所知,没有办法隐藏路径,因为 VS Code 集成终端基本上是在使用您的操作系统/系统的底层终端。 在终端上运行 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 扩展 - 它可以选择完全按照您的意愿进行操作:仅打印代码的 output,没有其他内容

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

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

例子:

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

暂无
暂无

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

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