7

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
3
  • If you need more information or screenshots I'll be happy to provide you with them. Commented Sep 24, 2019 at 18:07
  • Have you tried editing your PATH to include python.exe? Commented Sep 24, 2019 at 18:10
  • 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). Commented Sep 24, 2019 at 21:04

6 Answers 6

13

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

Sign up to request clarification or add additional context in comments.

Comments

2

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"

1 Comment

this is what I was looking for !
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.

Comments

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.

Comments

0

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.