How to Run Python in VSCode Smoothly

Summarize this article with:
You’ve installed Python. You’ve downloaded VSCode. Now what?
Learning how to run Python in VSCode takes about 5 minutes, but those 5 minutes determine whether your coding sessions feel smooth or frustrating.
Visual Studio Code handles Python development better than most code editors. The right setup gives you syntax highlighting, IntelliSense, and debugging tools out of the box.
This guide walks through installing the Python extension, selecting an interpreter, and executing your first script.
You’ll also learn terminal execution, debug configuration, and fixes for common errors.
Works on Windows, macOS, and Linux. No prior VSCode experience required.
How to Run Python in VSCode

Running Python in VSCode is the process of executing Python scripts and code files within Visual Studio Code, Microsoft’s free code editor.
You need this when building Python applications, testing scripts, or learning the language.
This guide covers 6 steps requiring 5 to 10 minutes and basic familiarity with code editors.
Prerequisites
Before you start, gather these requirements:
- Visual Studio Code version 1.85 or later installed on Windows, macOS, or Linux
- Python version 3.8 or later (download from python.org)
- Basic understanding of file management
- Administrator access for extension installation
Time estimate: 5 to 10 minutes for complete setup.
Step 1: How Do You Install the Python Extension in VSCode?
The Python extension adds language support, IntelliSense, and debugging tools to VSCode. Open the Extensions sidebar using Ctrl+Shift+X, search for “Python,” and install the Microsoft Python extension. The extension icon appears in your sidebar after installation completes.
Action
- Extensions sidebar (Ctrl+Shift+X): Click the square icon on the left or use the keyboard shortcut
- Search field: Type “Python” and locate the extension published by Microsoft
- Install button: Click Install and wait for the download to finish
Purpose
The Python extension enables syntax highlighting, code completion, and linting inside VSCode.
Without it, the editor treats Python files as plain text.
Step 2: How Do You Select a Python Interpreter?
Selecting an interpreter tells VSCode which Python installation to use for running scripts. Open the Command Palette with Ctrl+Shift+P, type “Python: Select Interpreter,” and choose your installed Python version from the dropdown list. The selected version displays in the status bar at the bottom.
Action
- Command Palette (Ctrl+Shift+P): Opens the command search interface
- Search: Type “Python: Select Interpreter”
- Interpreter list: Select Python 3.11 or your installed version
Purpose
Different projects may require different Python versions.
Need to switch versions later? Learn how to change the Python interpreter anytime through the same process.
Step 3: How Do You Create a Python File in VSCode?
Creating a Python file with the correct .py extension activates language features automatically. Press Ctrl+N to create a new file, then Ctrl+S to save with a .py extension. Syntax highlighting and code completion activate immediately after saving.
Action
- New file (Ctrl+N): Creates an untitled document in the editor
- Save dialog (Ctrl+S): Name your file with .py extension (example: main.py)
- Result: Python syntax highlighting activates in the editor window
Purpose
The .py extension signals VSCode to apply Python-specific features.
Files without this extension won’t receive IntelliSense or proper formatting.
Step 4: How Do You Write and Run Your First Python Script?
Writing and executing a test script confirms your Python setup works correctly. Type print("Hello, World!") in the editor, then click the Run button (triangle icon) in the top right corner or press F5. Output appears in the Terminal panel at the bottom of the window.
Action
- Editor window: Type
print("Hello, World!") - Run button (top right triangle) or F5: Executes the current Python file
- Terminal panel: Displays “Hello, World!” as output
Purpose
Running a simple script verifies that Python, the extension, and interpreter work together.
If you see the output, your development environment is ready.
Step 5: How Do You Run Python Code in the Integrated Terminal?
The integrated terminal provides direct access to Python commands and pip package management. Open it with Ctrl+ or through View > Terminal, then type python filename.py to execute any script. Script output displays directly in the terminal window.
Action
- Terminal menu > New Terminal (Ctrl+): Opens the integrated terminal
- Command line: Type
python main.py(replace with your filename) - Result: Script executes and output appears in terminal
Purpose
Terminal execution allows passing arguments to scripts and running pip commands.
Use this method when working with virtual environments or installing packages like matplotlib.
Step 6: How Do You Configure Python Debugging in VSCode?
Debug configuration enables breakpoints, variable inspection, and step-through execution. Open the Run and Debug sidebar with Ctrl+Shift+D, click “create a launch.json file,” and select “Python File” from the dropdown. VSCode creates a launch.json in the .vscode folder.
Action
- Run and Debug sidebar (Ctrl+Shift+D): Opens the debugging panel
- Create launch.json: Click the link to generate configuration
- Configuration type: Select “Python File” for basic debugging
Purpose
The launch.json file stores your debug settings for the project.
For advanced debugging techniques, check out how to debug Python in VSCode.
Verification
Confirm your setup works by checking these indicators:
- Python version displays in the VSCode status bar (bottom left)
- Running
print()produces output in the Terminal panel - No red error squiggles appear in valid code
- IntelliSense suggestions appear when typing
If any check fails, revisit the corresponding step above.
Troubleshooting
Python Not Recognized in Terminal
Issue: Terminal shows “python is not recognized” or “command not found.”
Solution: Add Python to your system PATH. On Windows: System Properties > Environment Variables > Path > Add Python installation directory (typically C:Python311).
Extension Fails to Detect Interpreter
Issue: No interpreters appear in the selection list.
Solution: Restart VSCode after Python installation, then rerun Python: Select Interpreter from the Command Palette.
Code Runs But No Output Appears
Issue: Script executes without visible results.
Solution: Verify the Terminal panel is visible through View > Terminal. Check that your code contains print statements.
Import Errors for Packages
Issue: ModuleNotFoundError when importing libraries.
Solution: Install pip if missing, then run pip install package_name in the terminal. Make sure you’re using the correct virtual environment.
Alternative Methods
Method A: Run Button
- Time: 1 click
- Best for: Single file execution, quick testing
Method B: Integrated Terminal
- Time: Manual command entry
- Best for: Running with arguments, virtual environment activation
Method C: Debug Mode
- Time: Initial configuration required
- Best for: Breakpoints, variable inspection, step-through execution
Related Processes
Continue building your Python development workflow:
- Running pytest in VSCode for unit testing
- Commenting multiple lines in Python for cleaner code
- Auto-formatting code with Black or autopep8
- Exiting virtual environments when switching projects
- Connecting VSCode to GitHub for source control
FAQ on How To Run Python In VSCode
Why is Python not running in VSCode?
The Python extension may be missing or your interpreter is not selected. Install the Microsoft Python extension from the marketplace, then use Ctrl+Shift+P and select “Python: Select Interpreter” to choose your Python version.
How do I run a Python file with the Run button?
Open your .py file in the editor. Click the triangle icon in the top right corner. Output displays in the Terminal panel. This method works for single-file execution without command line arguments.
Can I run Python in VSCode without installing Python?
No. VSCode requires a local Python installation to execute scripts. Download Python from python.org, install it with PATH enabled, then restart VSCode. The editor detects the interpreter automatically after installation.
How do I run Python in the VSCode terminal?
Press Ctrl+ to open the integrated terminal. Type python filename.py and press Enter. This method allows passing arguments and works well when managing packages or using virtual environments.
What is the keyboard shortcut to run Python in VSCode?
Press F5 to run with debugging enabled. For running without debugging, use Ctrl+F5. Both shortcuts execute the currently open Python file and display output in the Terminal or Debug Console.
How do I fix “Python was not found” error in VSCode?
Python is not in your system PATH. Reinstall Python and check “Add Python to PATH” during setup. Alternatively, manually add the Python directory to Environment Variables on Windows, then restart VSCode.
Can I run selected Python code instead of the entire file?
Yes. Highlight the code you want to execute. Right-click and select “Run Selection/Line in Python Terminal.” The selected code runs in the integrated terminal. Useful for testing snippets during software development.
How do I run Python with a virtual environment in VSCode?
Create a venv using python -m venv venv in the terminal. VSCode detects it automatically. Select the venv interpreter through the Command Palette. The status bar shows the active environment name.
Why does VSCode show import errors when the code runs fine?
The error squiggles appear when Pylance cannot find the module. Your interpreter may differ from the environment where packages are installed. Select the correct interpreter or install missing packages with pip.
How do I configure VSCode to run Python automatically on save?
VSCode does not run code on save by default. Install the “Code Runner” extension for this feature. Alternatively, use test-driven development with pytest watch mode for automatic test execution.
Conclusion
You now know how to run Python in VSCode using three different methods: the Run button, integrated terminal, and debug mode.
The setup takes minutes. The productivity gains last throughout your Python programming career.
VSCode handles everything from simple scripts to complex projects with virtual environments and pip package management.
Start with the Run button for quick execution. Move to terminal commands when you need arguments or environment control. Use debug mode with breakpoints when tracking down bugs.
The Command Palette and keyboard shortcuts speed up your development workflow significantly.
Keep the Python extension updated through the extension marketplace. Configure your workspace settings as projects grow. Your code editor should work for you, not against you.







