Get AI summaries of any video or article — Sign up free
Visual Studio Code (Windows) - Setting up a Python Development Environment and Complete Overview thumbnail

Visual Studio Code (Windows) - Setting up a Python Development Environment and Complete Overview

Corey Schafer·
5 min read

Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Install Visual Studio Code from code.visualstudio.com and add the Python extension to unlock Python linting, debugging, formatting, unit testing, and IntelliSense.

Briefing

Visual Studio Code becomes a full Python workstation on Windows by pairing the built-in editor with the Python extension, then wiring it to the right interpreter (global or per-project virtual environment) and enabling formatting, linting, debugging, Git, and unit tests. The practical payoff is fewer manual steps: code runs against the intended Python version, imports autocomplete as you type, and errors surface immediately through linting and test discovery.

Setup starts with installing Visual Studio Code from code.visualstudio.com, then using the Extensions panel to add the Python extension—highlighted as the most popular extension in the marketplace. Once installed, VS Code opens a project folder and prompts for a Python interpreter and linter availability. Running a script is straightforward via “Run Python file in terminal,” and the interpreter can be switched from the status bar. The walkthrough demonstrates why interpreter choice matters by showing the same script running under Python 3.7 versus Python 2.7, with VS Code updating the selected executable accordingly.

To make interpreter selection consistent, the guide moves from per-project settings to global user settings by editing settings.json. A key change is setting the default Python path so new projects automatically use Python 3.7. For project-specific dependencies, it then creates a virtual environment using the standard-library venv module (python -m venv venv) inside the project directory. VS Code auto-detects that venv folder and switches the interpreter to it, and terminal sessions inherit the activated environment—so pip installs land in the right place.

With the environment in place, the workflow tightens further. IntelliSense provides method and attribute suggestions (e.g., for the requests library) and supports “Go to definition” and “Peek definition” to inspect library code without leaving the editor. Auto-formatting is enabled by installing a formatter (the example uses black) and turning on format-on-save. Import sorting is handled via a “Sort Imports” command, which groups standard library imports separately from third-party ones.

Linting is added by installing a linter (pylint in the example). After enabling it, the editor underlines syntax and style issues—such as a Python 2-style print statement error—and also flags warnings like unused variables. For faster execution, an extension called Code Runner adds a Run button and a configurable execution mapping so it uses the current VS Code Python interpreter (the virtual environment) rather than the global one. The walkthrough also shows how to handle interactive input using the built-in terminal (input()) and running the file in terminal.

Source control integration follows: Git initialization happens through the Source Control view, with a .gitignore created to exclude venv and the .vscode workspace folder. Commits and pushes to GitHub are performed from VS Code, including configuring Git username/email and switching the integrated terminal to Git Bash.

Finally, VS Code’s debugging and testing features are demonstrated. Breakpoints are set in the gutter, then the Debug panel runs the current file and exposes local variables, watch expressions, and an interactive debug console. Unit testing support is enabled by discovering tests, selecting a framework (the example uses unittest), and running individual tests, test classes, or rerunning failed tests with detailed output and line-level failure locations. The result is a cohesive Python development loop—edit, format, lint, run, debug, test, and version-control—within one environment.

Cornell Notes

The walkthrough shows how to turn Visual Studio Code into a Windows-based Python development environment by installing the Python extension, selecting the correct interpreter, and using per-project virtual environments. It then layers in productivity features: IntelliSense for code completion and navigation, auto-formatting (black) and import sorting, and linting (pylint) to catch errors and warnings early. For reliability, it demonstrates debugging with breakpoints and interactive inspection, plus unit test discovery and running via VS Code’s testing UI. Git integration ties the workflow together by initializing a repository, ignoring venv and workspace settings, committing changes, and pushing to GitHub.

Why does interpreter selection matter in VS Code, and how does the setup ensure the right Python runs?

VS Code can run the same script under different installed Pythons (e.g., Python 3.7 vs Python 2.7). The guide shows switching interpreters from the status bar and then makes the choice stick by setting a default Python path in global settings.json. For project-specific correctness, it creates a virtual environment with python -m venv venv and then selects the venv interpreter; VS Code auto-detects that venv folder and activates it for new terminal sessions, so pip installs and runs stay aligned.

What does IntelliSense add beyond basic syntax highlighting?

IntelliSense provides attribute/method suggestions while typing (e.g., after request. it lists available calls like get, post, and session). It also supports navigation: right-clicking a symbol enables Go to definition and Peek definition, letting the developer inspect how a library function is implemented without leaving the editor.

How are formatting and import organization automated?

A formatter is installed (the example uses black) and formatting is triggered with Shift+Alt+F, then made automatic by enabling format on save in user settings. Import organization is handled by a Sort Imports command, which alphabetizes imports and separates standard-library imports from third-party packages (e.g., requests grouped away from os).

How do linting and debugging complement each other?

Linting (installed via pylint) flags issues directly in the editor—syntax problems like missing parentheses in print, plus warnings such as unused variables—using red underlines for errors and green underlines for warnings. Debugging then lets the developer pause execution at breakpoints and inspect live state: local variables, watch expressions, and an interactive debug console to evaluate expressions like r.status_code at the breakpoint.

What’s the role of Code Runner, and how is it configured to use the virtual environment?

Code Runner adds a Run button and quick execution, but by default it may use the global interpreter. The guide fixes this by editing Code Runner’s code-runner.executorMap settings so Python executions use the current VS Code Python path and the full filename, plus options like clearing previous output and hiding execution messages. After that, running the script uses the venv interpreter and can successfully import packages installed only in the virtual environment.

How does VS Code’s unit testing workflow work in practice?

Unit testing is enabled by discovering tests (discover tests) and configuring the test framework (the example selects unittest). The guide specifies a naming pattern (test_*.py) and runs either a single test or an entire test class from inline controls. When an assertion fails, VS Code shows failure counts, test output, and the exact line number causing the assertion error; rerunning after saving updates results. A Testing tab provides a persistent pass/fail view and rerun options.

Review Questions

  1. When would you prefer setting a global default Python path versus creating a virtual environment per project?
  2. What specific configuration changes ensure Code Runner uses the same interpreter as VS Code’s selected Python (especially the venv)?
  3. How do linting errors/warnings differ from debugging breakpoints in terms of what information they provide?

Key Points

  1. 1

    Install Visual Studio Code from code.visualstudio.com and add the Python extension to unlock Python linting, debugging, formatting, unit testing, and IntelliSense.

  2. 2

    Use the status bar interpreter selector to verify which Python executable runs your code, then make it consistent by setting python.defaultInterpreterPath in global settings.json.

  3. 3

    Create per-project virtual environments with python -m venv venv so dependencies installed with pip stay isolated and reproducible.

  4. 4

    Enable productivity features: install a formatter (black), turn on format on save, and use Sort Imports to keep import blocks organized.

  5. 5

    Add linting (pylint) to surface errors and warnings directly in the editor, reducing reliance on manual print statements.

  6. 6

    Use VS Code debugging with breakpoints to inspect locals, watch variables, and evaluate expressions in the debug console at runtime.

  7. 7

    Integrate Git and GitHub inside VS Code by initializing a repository, adding a .gitignore for venv and .vscode, committing changes, and pushing to a remote origin.

Highlights

The Python extension’s interpreter switching is the foundation: the same script can run under Python 2.7 or Python 3.7 depending on the selected executable.
Creating a venv inside the project makes VS Code auto-detect the environment and activate it for new terminal sessions, keeping pip installs and runs consistent.
Black + format-on-save turns code cleanup into a one-step habit, while Sort Imports keeps standard-library and third-party imports separated.
Code Runner needs explicit configuration to use the virtual environment; otherwise it may run with the global interpreter and fail when packages aren’t installed globally.
VS Code’s testing UI supports discovery, running single tests or whole classes, and shows line-level assertion failures with rerun options.

Topics

Mentioned

  • Corey Schafer
  • VS Code
  • IDE
  • IDEA
  • Git
  • JSON
  • UI
  • UI version
  • v/s code
  • vscode
  • pip
  • venv
  • VS Code
  • IntelliSense
  • Pylint
  • PEP
  • IDEA
  • CLI
  • API
  • URL
  • HTTP
  • CMD
  • Git Bash
  • Zen mode
  • UI