To set up Python in VS Code on Windows, install the Python interpreter, install VS Code’s Python extension, choose the interpreter VS Code should use, and run a saved .py file. These are separate pieces, so installing the editor alone will not make Python available. Follow the steps below in order, and if Windows says Python was not found, use the checks near the end.
Understand the three parts of a Python setup
It helps to know what each tool does before installing anything:
- Python interpreter: The program that reads and runs your Python code. It must be installed separately.
- Visual Studio Code (VS Code): The editor where you create and edit files.
- VS Code’s Python extension: An add-on that helps VS Code work with Python, including selecting an interpreter and running code.
The extension does not install Python for you. If one piece is missing, the other two can appear to work while your program still will not run.
Install Python on Windows 11
-
Open Microsoft’s Python on Windows for beginners. It covers command-line and manual installation options. Choose one route and follow its instructions from beginning to end rather than combining steps from different methods.
-
If you prefer to get an installer directly, use the official Python releases for Windows page. Follow the instructions for the release and installer you choose. Avoid downloading an installer from an unfamiliar third-party site.
-
When installation finishes, open PowerShell and check whether Windows can find Python. Run:
python --versionA version response is a useful sign that the command is available in that shell. If it is not recognized, try the Windows launcher as described in the troubleshooting section.
If you have just installed Python, close and reopen PowerShell or the VS Code terminal before checking again. A terminal that was already open may not yet detect the new installation.
Install VS Code and its Python extension
-
Download and install VS Code using Microsoft’s Windows installation instructions. The documentation recommends User setup for most people because it does not require administrator permissions.
-
Open VS Code, go to the Extensions view, and search for Python. Install the Python extension. This adds Python support to the editor; it does not replace the interpreter you installed in the previous step.
-
Close and reopen VS Code after installing Python if it was open already. Restarting gives the editor and its terminal a fresh chance to detect the interpreter.
For more background on how the editor, extension, and interpreter work together, see the VS Code Python quick start.
Create a first Python file and select an interpreter
-
Make a folder for your practice project, then open it in VS Code using File > Open Folder. A project folder keeps your file easy to find and gives VS Code a clear place to work.
-
Create a new file named
hello.py. Check that the file ends in.py; that extension identifies it as a Python source file. -
Type this line and save the file:
print('Hello, world!')The
printfunction asks Python to display the text. Saving the file matters: the terminal runs the saved file, not unsaved text in the editor. -
Choose which installed Python VS Code should use. Open the Command Palette and run Python: Select Interpreter, then select the Python installation you intend to use. This matters if more than one interpreter is available: VS Code needs to know which one is associated with your work.
Run a Python file in the VS Code terminal
Open a fresh terminal in VS Code from Terminal > New Terminal. Make sure it is working in the folder that contains hello.py, then enter:
python hello.py
Press Enter. If the setup is working, the terminal displays:
Hello, world!
This command tells Python to run the saved file. It is different from typing python by itself, which may open an interactive Python prompt instead. If you see a prompt that begins with >>>, you are inside that interactive prompt, not at the PowerShell command line. Type exit() to leave it, then run the file command in the terminal.
Fix “Python was not found” in Windows or VS Code
That message means the command you tried could not find Python. It does not necessarily mean your .py file is wrong. Work through these checks in order:
-
Try the version check in a new terminal. Run
python --versionin PowerShell or a newly opened VS Code terminal. If Python was installed while the terminal was open, restarting the terminal or VS Code may be enough for it to detect the installation. -
Try the Windows launcher. If
python --versionis not recognized, enterpy --version. The Windows launcher can provide another way to reach an installed Python. If it returns a version, try running your file withpy hello.py. -
Check that Python is installed. The VS Code extension is not the interpreter. If neither version command works, revisit the installation instructions you chose and confirm that Python installation completed. Use the official Microsoft beginner guide or Python.org Windows page rather than mixing installation methods.
-
Select the interpreter again in VS Code. If a version command works in PowerShell but VS Code still cannot run the file, use Python: Select Interpreter and choose the installation you verified. Restart VS Code and check the selection again if the interpreter is not available.
-
Confirm you are running the file, not typing Python code at the prompt. Enter
python hello.pyor, when appropriate,py hello.pyat the terminal prompt. Do not enter that command after>>>; that prompt is waiting for Python code.
If neither python nor py works, the issue is with finding or completing the interpreter installation—not with the text in hello.py. Return to the official installation guide and follow one of its supported setup routes.
Quick success checklist
- Python is installed separately from VS Code and its extension.
python --versionor, where available,py --versionreturns a version in a fresh terminal.- VS Code’s Python extension is installed and an interpreter is selected.
hello.pyis saved in your project folder.- Running
python hello.pyorpy hello.pydisplaysHello, world!.
Once those checks pass, you have completed the basic setup. To set up Python in VS Code on Windows successfully, keep the interpreter, extension, and editor distinct—and test by running a saved .py file from the terminal.
Sources
Keep this guide handy
Share it or save the link for later.