Setting Up Visual Studio Code (VS Code) for Python Development

Markdown

View as Markdown

Visual Studio Code (VS Code) is one of the most popular code editors for Python development. It provides features such as syntax highlighting, code completion, debugging, extensions, and integrated terminal support, making it an excellent choice for beginners and professional developers alike.

Prerequisites

Before setting up VS Code for Python development, ensure the following are installed:

  • Python 3.x

  • Visual Studio Code

  • Internet connection (for downloading extensions)

Step 1: Download Visual Studio Code

Open your web browser and visit:

https://code.visualstudio.com/

Click Download for Windows, Download for macOS, or Download for Linux depending on your operating system.

Step 2: Install Visual Studio Code

Run the downloaded installer.

Windows Installation

  1. Accept the license agreement.

  2. Click Next.

  3. Select the installation location.

  4. Click Next.

  5. Check the following options:

    • Add "Open with Code" action

    • Add to PATH (recommended)

  6. Click Install.

Step 3: Launch VS Code

After installation, open Visual Studio Code.

You will see the Welcome screen.

 Step 4: Install the Python Extension

The Python extension provides IntelliSense, debugging, code navigation, and many other Python development features.

Install the Extension

  1. Click the Extensions icon on the left sidebar.

  2. Search for:  Python

  3. Locate the extension published by Microsoft.

  4. Click Install.

Step 5: Verify Python Extension Installation

After installation, the extension should display:

Installed

Step 6: Create a Python Project Folder

Create a folder named:  PythonProjects  or any preferred project name.

Open VS Code and select:

File → Open Folder

Choose the newly created folder.

Step 7: Create Your First Python File

Inside VS Code:

  1. Click New File.

  2. Name the file:

hello.py

  1. Enter the following code:

print("Hello World")

Step 8: Select the Python Interpreter

Press:

Ctrl + Shift + P

Search for:

Python: Select Interpreter

Select the installed Python version.

Example:

Python 3.14.5 64-bit

Step 9: Run the Python Program

Click the Run button (▶) in the top-right corner.

Alternatively, right-click inside the editor and select:

Run Python File

Step 10: View Program Output

The integrated terminal will open automatically and display:

Hello World

Step 11: Open the Integrated Terminal

VS Code includes a built-in terminal.

Open it using:

Terminal → New Terminal

Or  Ctrl + `

The terminal opens at the bottom of the editor.

Step 12: Run Python from the Terminal

In the terminal, run:  python hello.py

Expected output: Hello World

Step 13: Install Additional Recommended Extensions

For a better Python development experience, consider installing:

Extension

Purpose

Python

Python language support

Pylance

Advanced IntelliSense

Jupyter

Notebook support

GitHub Copilot

AI-assisted coding

Code Runner

Run code quickly

Troubleshooting Common Issues

1.       Python Interpreter Not Found

Solution

  1. Open Command Prompt.

  2. Verify Python installation:

python --version

  1. Restart VS Code.

  2. Select the interpreter again.

2. Python Extension Missing

Solution

Open Extensions and reinstall the Python extension published by Microsoft.

3.Terminal Shows Command Not Found

Solution

Ensure Python is added to the system PATH and restart VS Code.

Verify:

python --version

4. Run Button Not Appearing

Solution

Install or reinstall the Python extension and reopen the Python file.

Verify Your Setup

Create a new file:

name = "Python"

print("Welcome to", name)

Run the file.

Expected output:

Welcome to Python

If the output appears correctly, VS Code is successfully configured for Python development.

Was this article helpful?

Still need help?

Contact us