Visual Studio Code not running Python
Asked Answered
M

6

5

I'm using the newest version of Visual Studio Code and Python 3.6 (64 bit) on Windows 10.

I have the "Python" extension installed (the one made by Microsoft).

Every time I try to run a simple program [e.g., print("Hello, World!")] it says that "The command "python" wasn't spelled correctly or couldn't be found"! [Done] exited with code=1 in 0.034 seconds

It's a very simple Hello, World! program that doesn't really need much. Why is Visual Studio Code not letting me run a Python file?

This is where my Python executable is stored:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe
Macule answered 24/9, 2019 at 18:6 Comment(3)
If you need more information or screenshots I'll be happy to provide you with them.Macule
Have you tried editing your PATH to include python.exe?Atahualpa
It appears you have the Code Runner extension installed and that's what's not working, not the Python extension from Microsoft (the [Done] is a tell-tale sign).Skat
S
11

Maybe there is problem with your interpreter.

Try this: Ctrl + Shift + PPython: Select Interpreter → select your path (C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe)

https://code.visualstudio.com/docs/python/environments

Schoonmaker answered 24/9, 2019 at 18:35 Comment(0)
Z
1

If you have installed Python from an executable file and not from the Windows Store, you can change your terminal setting from internal to external and make cmd as the default terminal in Visual Studio Code.

You can directly edit those setting from settings.json:

"terminal.explorerKind": "external",
"terminal.integrated.defaultProfile.windows": "Command Prompt"
Zoes answered 12/7, 2021 at 18:47 Comment(0)
K
1

I had the same problem and I've just solved it!

instead of opening your python file directly, open a folder that contains your python file. This way a workplace will be opened and Vscode will ask you if you trust this workplace. Once you choose that you do trust it, it will let you run and debug your python files in that folder.

Krouse answered 28/1 at 8:48 Comment(0)
A
0

I needed to do the equivalent of blowing in the NES cartridge...

IN VSCode, next to the "Run" icon, there is a drop down arrow. Hit the dropdown arrow and select "Run Python File"

After that, running the code (Clicking the arrow) worked as expected.

I could not find this anywhere online. I hope this helps someone.

Anatto answered 19/9, 2023 at 10:11 Comment(0)
G
0

On the bottom left of your screen, check if it is showing "Restricted Mode". If it is, exit the Restricted Mode.

Gaut answered 21/1 at 14:21 Comment(0)
G
0

In My case I was able to see "Run Python" option on right click with python file on Visual Studio after installing the extensions : Python and Pylance

enter image description here

Geostrophic answered 9/10 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.