【问题标题】:VS Code is not running Python Programs and is showing a Powershell Advert on the Terminal and the Terminal is not showing the pathVS Code 未运行 Python 程序,并且在终端上显示 Powershell 广告,并且终端未显示路径
【发布时间】:2021-01-26 10:04:09
【问题描述】:

当我点击“在终端中运行 Python 文件”时,它什么也不做,没有错误,什么都没有,但如果我用 python IDLE 运行同一个文件,它就可以工作,我重新安装了最新版本Python 和 VS Code,但问题仍然没有解决。 此外,终端会显示 Powershell 广告,并且不会像通常那样显示路径。

编辑:Powershell 显示广告并且无法正常工作

代码在CMD中正常运行

我使用的 VS Code 扩展是:

  1. 括号对着色器
  2. 代码运行器
  3. Jupyter(我知道它的作用,但 VS Code 提示我为 Python 安装它)
  4. 实时服务器
  5. 材质图标主题
  6. Pylance(我知道它的作用,但 VS Code 提示我为 Python 安装它)
  7. 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,我没有遇到任何问题。

【问题讨论】:

  • 点击右上角的绿色运行符号会发生什么?
  • @Shivansh Sahu - 你能在 VS Code 之外的 cmd 终端中运行这段代码吗?您能否提供一下您使用的 VS Code 扩展以及设置文件“settings.json”的内容?
  • @JillCheng 编辑了问题

标签: python visual-studio-code


【解决方案1】:

根据你提供的信息,问题是系统自带的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:

参考:Integrated terminal in VS Code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-23
    • 2021-04-18
    • 2022-11-14
    • 2021-11-15
    • 2022-10-03
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多