如何清除VS Code终端中Python运行时的路径等冗余内容
清除VS Code运行Python时终端的冗余内容
方法一:改用调试控制台输出
- 打开VS Code的「运行和调试」面板(快捷键:Ctrl+Shift+D)
- 点击「创建launch.json文件」,选择Python环境
- 在生成的
launch.json配置中,将console字段设置为internalConsole,示例配置如下:
{ "version": "0.2.0", "configurations": [ { "name": "Python: 当前文件", "type": "python", "request": "launch", "program": "${file}", "console": "internalConsole" } ] }
配置完成后,运行代码时结果会输出到「调试控制台」,仅显示程序运行内容,无终端冗余信息。
方法二:修改PowerShell启动参数
- 打开VS Code设置(快捷键:Ctrl+,)
- 搜索
terminal.integrated.profiles.windows,找到PowerShell的配置项 - 修改其
args为["-NoLogo", "-Command", "& '${command:python.interpreterPath}' '${file}'"],同时设置默认终端为PowerShell,示例配置:
"terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "args": ["-NoLogo", "-Command", "& '${command:python.interpreterPath}' '${file}'"] } }, "terminal.integrated.defaultProfile.windows": "PowerShell"
-NoLogo参数会移除PowerShell启动时的版权提示,直接执行Python命令,减少路径等冗余输出。
方法三:使用Code Runner插件
- 在VS Code扩展市场安装「Code Runner」插件
- 打开插件设置,找到「Code Runner: Run In Terminal」选项并取消勾选
- 运行代码时,结果会输出到「输出」面板,仅保留程序运行结果。
内容的提问来源于stack exchange,提问作者Dimuth De Zoysa
相关产品推荐
相关产品推荐

