If you’re starting your Python journey or want a lightweight yet powerful coding environment, Visual Studio Code (VS Code) is one of the best tools available. It’s fast, customizable, and integrates seamlessly with Python to provide an excellent development experience.
In this guide, we’ll show you how to install and set up VS Code for Python on Windows 11 — step by step. By the end, you’ll have a fully configured environment ready to write, run, and debug Python code.
Why Use Visual Studio Code for Python?
Visual Studio Code, developed by Microsoft, is one of the most popular text editors for developers — and for good reason. When combined with the Python extension, it turns into a full-fledged IDE.
Benefits of Using VS Code for Python:
- Lightweight and fast — unlike heavy IDEs like PyCharm.
- Extensions and customization for any workflow.
- IntelliSense — smart code completion and suggestions.
- Built-in debugger for easy error tracking.
- Integrated terminal for running Python scripts directly.
- Cross-platform — works on Windows, macOS, and Linux.
Step 1: Install Python on Windows 11
Before setting up VS Code, ensure that Python is installed on your system.
Steps to Install Python:
- Go to the official Python website: https://www.python.org/downloads/
- Click on Download Python 3.x.x (latest version).
- Run the downloaded installer.
- In the setup window, make sure to check:
- ✅ Add Python to PATH
- ✅ Install for all users
- Click Install Now and wait for the installation to finish.
Verify the Installation:
Open Command Prompt (CMD) and type:
python --version
If Python is installed correctly, you’ll see something like:
Python 3.12.1
Pro Tip: If you get an error like “Python not recognized”, you may need to add it manually to your PATH — see How to Add Python to PATH on Windows 11.
Step 2: Download and Install Visual Studio Code
Once Python is installed, let’s set up Visual Studio Code.
- Visit the official download page: https://code.visualstudio.com/
- Click Download for Windows.
- Run the installer and follow the setup wizard.
- During installation, check these options:
- ✅ Add “Open with Code” to File Explorer context menu.
- ✅ Add to PATH (so you can open VS Code from CMD).
After installation, launch VS Code.
Step 3: Install the Python Extension in VS Code
VS Code doesn’t support Python out of the box — you’ll need to install the Python extension from Microsoft.
- Open VS Code.
- Click on the Extensions icon on the left sidebar (or press
Ctrl + Shift + X). - In the search bar, type:
Python - Install the extension published by Microsoft (it should be the top result).
- Once installed, reload VS Code.
Pro Tip: The Python extension automatically adds support for IntelliSense, Linting, Jupyter Notebooks, and Debugging.
Step 4: Install the Python Extension Pack (Optional but Recommended)
For a complete Python development setup, install the Python Extension Pack — it bundles multiple tools useful for coding, formatting, and linting.
Includes:
- Python (by Microsoft)
- Pylance (for better IntelliSense)
- Jupyter
- Python Debugger
- Black Formatter
- isort (import sorter)
To install:
- Go to the Extensions tab again.
- Search for:
Python Extension Pack - Click Install.
Step 5: Configure the Python Interpreter
VS Code needs to know which Python installation or virtual environment to use.
To select the interpreter:
- Open a Python file or create a new one (e.g.,
test.py). - Press Ctrl + Shift + P to open the Command Palette.
- Type:
Python: Select Interpreter - Select the interpreter you installed earlier (e.g.,
Python 3.12 (C:\Python312\python.exe)).
If you have multiple Python versions installed, choose the one you want to use for your current project.
Step 6: Create Your First Python File
Now that everything’s ready, let’s create and run a simple Python script.
- In VS Code, click File → New File.
- Save it as
hello.py. - Add this code:
print("Hello, Python from VS Code!") - Click Run at the top-right corner, or open the integrated terminal (
Ctrl + ~) and type:python hello.py
You should see:
Hello, Python from VS Code!
Step 7: Set Up Virtual Environments (Recommended)
Virtual environments help keep your project dependencies isolated — a must for managing multiple Python projects.
To create a virtual environment:
- Open the Terminal in VS Code (
Ctrl + ~). - Navigate to your project folder:
cd path\to\your\project - Create a virtual environment:
python -m venv venv - Activate it:
venv\Scripts\activate - Install any dependencies you need:
pip install requests
Tip: When a virtual environment is activated, VS Code automatically detects it and uses it as the project’s Python interpreter.
Step 8: Enable Linting and Auto-Formatting
Code linting helps you detect potential issues and maintain clean code automatically.
Enable Linting:
- Press Ctrl + Shift + P → search for:
Python: Enable Linting - Select Yes.
- Choose a linter (like
pylintorflake8).
Enable Auto-Formatting:
- Go to File → Preferences → Settings (
Ctrl + ,). - Search for “format on save”.
- Enable:
Editor: Format On Save - Select a formatter:
Python > Formatting: Provider → Black
Now, your code will automatically format and highlight syntax issues as you type.
Step 9: Install Useful Python Extensions (Optional)
Here are a few more handy extensions for Python development in VS Code:
| Extension | Purpose |
|---|---|
| Pylance | Fast IntelliSense and type checking |
| Jupyter | Run Python notebooks inside VS Code |
| Black Formatter | Consistent code formatting |
| isort | Organize imports automatically |
| Python Test Explorer | Manage and run Python tests |
| Prettier | General code formatter |
Step 10: Debug Your Python Code
VS Code’s built-in debugger makes it easy to inspect variables and fix bugs.
To debug:
- Click on the Run and Debug icon (or press
Ctrl + Shift + D). - Select Python File as the configuration.
- Set breakpoints by clicking next to the line numbers.
- Press F5 to start debugging.
You can inspect variables, view the call stack, and step through your code interactively.
Step 11: Run Python Code in Jupyter Notebooks (Optional)
VS Code supports Jupyter Notebooks (.ipynb) directly.
- Install the Jupyter extension (if not already).
- Open or create a
.ipynbfile. - You’ll see Run Cell options above each code block.
- Execute your cells interactively — just like in JupyterLab.
Pro Tip: Perfect for data science, ML, or AI projects.
Wrapping Up
That’s it! You’ve now successfully learned how to set up Visual Studio Code for Python on Windows 11.
With the Python extension, IntelliSense, virtual environments, and integrated debugging, VS Code gives you a powerful yet simple Python development setup.
Whether you’re learning Python, building AI models, or developing full-stack web apps — this setup will help you code smarter, faster, and cleaner.