簡體   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