Visual Studio Code (Windows) - Setting up a Python Development Environment and Complete Overview
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.
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?
What does IntelliSense add beyond basic syntax highlighting?
How are formatting and import organization automated?
How do linting and debugging complement each other?
What’s the role of Code Runner, and how is it configured to use the virtual environment?
How does VS Code’s unit testing workflow work in practice?
Review Questions
- When would you prefer setting a global default Python path versus creating a virtual environment per project?
- What specific configuration changes ensure Code Runner uses the same interpreter as VS Code’s selected Python (especially the venv)?
- How do linting errors/warnings differ from debugging breakpoints in terms of what information they provide?
Key Points
- 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
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
Create per-project virtual environments with python -m venv venv so dependencies installed with pip stay isolated and reproducible.
- 4
Enable productivity features: install a formatter (black), turn on format on save, and use Sort Imports to keep import blocks organized.
- 5
Add linting (pylint) to surface errors and warnings directly in the editor, reducing reliance on manual print statements.
- 6
Use VS Code debugging with breakpoints to inspect locals, watch variables, and evaluate expressions in the debug console at runtime.
- 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.