python - VS Code 未运行 Python 程序,并且在终端上显示 Powershell 广告,并且终端未显示路径
问题描述
一旦我单击“在终端中运行 Python 文件”,它什么也不做,没有错误,什么都没有闲置,但是如果我使用 python IDLE 运行相同的文件,它就可以工作,我重新安装了最新版本的 Python 和VS Code,但问题仍然没有解决。此外,终端会显示 Powershell 广告,并且不会像通常那样显示路径。
编辑:Powershell 显示广告并且无法正常工作
代码在 CMD 中正常运行
我使用的 VS Code 扩展是:
- 括号对着色器
- 代码运行器
- Jupyter(我知道它做了什么,但 VS Code 提示我为 Python 安装它)
- 直播服务器
- 材质图标主题
- Pylance(我知道它做了什么,但 VS Code 提示我为 Python 安装它)
- Python
这是 settings.json 的内容
{
"editor.fontSize": 18,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"window.zoomLevel": -1,
"workbench.colorTheme": "Default Dark+",
"workbench.editorAssociations": [],
"python.languageServer": "Pylance",
"editor.mouseWheelZoom": true,
"code-runner.clearPreviousOutput": true,
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.saveFileBeforeRun": true
}
由于这个问题,我忽略了 VS Code 并安装了 PyCharm,我没有遇到任何问题。
解决方案
根据你提供的信息,问题是系统自带的powershell终端无法使用。因为 VS Code 是一个编辑器,它的内部 powershell 终端集成了系统的 powershell 终端。不过VS Code不仅支持这个终端,还支持cmd终端、bash等。
解决方案:由于可以在 VS Code 之外的 cmd 终端中运行 python 代码,请使用
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
代替
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
在 VS Code 的“settings.json”中将终端切换到 cmd。
或者你可以使用下面的方法,也可以将终端切换到cmd:
参考: VS Code 中的集成终端。
推荐阅读
- keyboard-shortcuts - 创建简单绑定键盘快捷键的 Wayland 桌面环境
- image - 未找到 image::ImageBuffer::from_vec() 的函数或相关项
- spotfire - 列到行并突出显示同一组中值之间的差异
- c - C中的Typedef和struct
- reactjs - DHTMLXGantt 与 ReactJS 设置 work_time
- google-apps-script - 如何从 API 获取 Google Apps 脚本文档大纲?
- powerbi - 根据powerbi中的列添加动态常数行
- excel - 如果满足另一列中的条件,则计算两个日期之间的天数
- javascript - 即时生成 javascript 和 html 块
- html - 显示柔性行和统一尺寸