Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

VS Code is not running Python Programs and is showing a Powershell Advert on the Terminal and the Terminal is not showing the path

Problem

As soon as I click 'Run Python File in Terminal', it does nothing, no errors, nothing just remains idle, but if I run the same file with the python IDLE, it works, I re-installed the latest version of Python and VS Code but still the problem isn't solved. Also, the Terminal shows a Powershell advert and doesn't show the path like it usually should.

Edit: Powershell shows an advert and doesn't work properly

Powershell

The code runs properly in CMD

CMD

The VS Code extensions I use are:

  1. Bracket Pair Colorizer
  2. Code Runner
  3. Jupyter (Idk what it does but VS Code prompted me to install it for Python)
  4. Live Server
  5. Material Icon Theme
  6. Pylance (Idk what it does but VS Code prompted me to install it for Python)
  7. Python

This is the content of 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
}

Because of this problem, I ignored VS Code and installed PyCharm and I am having no issues with it.

question from:https://stackoverflow.com/questions/65899266/vs-code-is-not-running-python-programs-and-is-showing-a-powershell-advert-on-the

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to the information you provided, the problem is that the powershell terminal that comes with the system cannot be used. Because VS Code is an editor, its internal powershell terminal integrates the powershell terminal from the system. However, VS Code not only supports this terminal, it also supports cmd terminal, bash and so on.

Solution: Since you can run python code in cmd terminal outside of VS Code, please use

 "terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe",

instead of

"terminal.integrated.shell.windows": "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe",

in "settings.json" in VS Code to switch the terminal to cmd.

Or you could use the following method, which can also switch the terminal to cmd:

enter image description here

Reference: Integrated terminal in VS Code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...