VSCode

How to Set Up VSCode for Python Development

How to Set Up VSCode for Python Development

Most developers who set up VSCode for Python the wrong way spend weeks dealing with broken autocomplete, the wrong interpreter, and formatters that refuse to run on save.

Visual Studio Code has become the go-to code editor for Python development, used by 73.6% of developers worldwide. But it does not work well out of the box for Python – it needs the right extensions, interpreter setup, and workspace configuration.

This guide covers everything that actually matters: setting up the Python extension, configuring Pylance and IntelliSense, linting with Ruff or Pylint, debugging with debugpy, running tests with pytest, and using Jupyter notebooks – all inside VSCode.

VSCode for Python

Visual Studio Code is a lightweight code editor built by Microsoft. It is not a full IDE out of the box – it becomes one through extensions, and that distinction matters a lot when you are setting up a Python environment for the first time.

Python is used by 51% of all developers surveyed in the 2024 Stack Overflow Developer Survey, making it the third most-used language overall. It also ranked as the single most desired language among people learning to code.

The gap between VSCode and competitors is real. According to the same survey, 73.6% of developers use VSCode, while its nearest alternative sits at roughly 30%. For Python work specifically, the Python extension, Pylance, and Jupyter together account for over 360 million installs on the VS Code Marketplace.

VSCode vs PyCharm for Python

Key difference: PyCharm ships with Python-specific features built in. VSCode requires you to build that layer yourself via extensions.

That is not necessarily a problem. Plenty of developers prefer VSCode precisely because it stays out of the way until you need something. The trade-off is a longer initial setup.

VS CodePyCharm
Python supportVia extensionsBuilt-in
Startup speedFastSlower
Memory usageLowerHigher
CostFreeFree (Community) / Paid (Pro)
Jupyter supportExtensionBuilt-in (Pro only)

For front-end development that also touches Python back-end code, VSCode wins on flexibility. For dedicated Python work only, PyCharm’s built-in tooling is hard to beat.

What you get out of the box

A fresh VSCode install gives you syntax highlighting for Python files and almost nothing else. No linting, no autocomplete beyond basic text matching, no debugger.

  • Syntax highlighting for .py files
  • Basic file explorer and integrated terminal
  • Git integration
  • Extensions marketplace with 60,000+ available tools

Everything else – IntelliSense, virtual environment management, the Python interpreter selection, linting, formatting – comes from extensions you install manually.

How to Set Up Python in VSCode

maxresdefault How to Set Up VSCode for Python Development

Getting Python working properly in VSCode takes about ten minutes if you know what you are doing. If you skip steps, expect broken autocomplete and interpreter confusion later.

Microsoft’s Python extension (identifier: ms-python.python) is the starting point. Install it from the extensions sidebar or via Ctrl+Shift+X. VSCode will usually prompt you automatically when you open a .py file for the first time.

Selecting the Python Interpreter

The most common setup mistake is skipping interpreter selection. VSCode might pick up the wrong Python version – especially on machines with multiple versions installed.

Open the Command Palette with Ctrl+Shift+P, type Python: Select Interpreter, and pick the version you actually want. The selected interpreter appears in the bottom status bar.

Every shortcut and workflow trick from this guide - including Ctrl+P for quick open, Ctrl+Shift+P for the command palette, and the full grid of keyboard shortcuts - is on one page in the VS Code Workflow Cheat Sheet.

Common issues developers run into:

  • VSCode picks the system Python instead of a project venv
  • Conda environments not showing up (requires the Anaconda extension or manual path)
  • pyenv versions not detected automatically without the python.defaultInterpreterPath setting

The August 2024 Python extension release introduced a native Python environment discovery tool that reduces the need to execute Python binaries just to probe version information – speeding up interpreter detection on large machines.

Setting Up a Virtual Environment in VSCode

VSCode detects virtual environments automatically when they live inside the workspace folder. Create one from the integrated terminal and VSCode will pick it up on next reload.

Steps that actually work:

  • Run python -m venv .venv in the terminal inside VSCode
  • VSCode prompts you to select it as the workspace interpreter – click Yes
  • Confirm it in the status bar: you should see .venv listed
  • For conda or pyenv environments, set python.defaultInterpreterPath in settings.json

Workspace-level interpreter settings go in .vscode/settings.json. User-level settings apply globally across all projects – useful for a default fallback, not for per-project isolation.

The software development process for Python projects almost always involves isolated environments. Skipping this step causes dependency conflicts that are genuinely annoying to debug later.

Best VSCode Extensions for Python

maxresdefault How to Set Up VSCode for Python Development

The Python extension marketplace has no shortage of options. Most of them are either redundant or narrow. These are the ones that actually change how you work day-to-day.

Black Formatter saw 89.45% growth in 2024 and became the most-installed Python tools extension in the VS Code Marketplace, according to Microsoft’s 2024 Python VS Code Wrapped report. Pylint grew by 70.71% and mypy topped the chart at 236.18% download growth.

Core Extensions Worth Installing

Pylance (ms-python.vscode-pylance): The language server that powers IntelliSense. Installed automatically with the Python extension since May 2021. Handles type checking, import resolution, and autocomplete.

Python Debugger (ms-python.debugpy): Separated from the main Python extension in 2024. Handles breakpoints, call stack inspection, and inline variable values during debug sessions.

Jupyter (ms-toolsai.jupyter): Runs .ipynb notebooks directly inside VSCode. Includes a variable explorer and data viewer for pandas DataFrames.

Linting and Formatting Extensions

Ruff is the practical choice right now. It combines linting and formatting into a single fast tool, replaces both Flake8 and Black in most setups, and runs significantly faster than either.

ExtensionPurposeReplaces
RuffLinting + formattingFlake8, Black, isort
Black FormatterFormatting onlyautopep8
PylintDeep code analysisFlake8 (partially)
mypyStatic type checking

If you are starting fresh in 2024 or 2025, install Ruff and skip the rest. If you are working on an existing project that already uses Black and Pylint, keep them – no need to migrate just because Ruff exists.

IntelliSense and Autocompletion for Python in VSCode

maxresdefault How to Set Up VSCode for Python Development

IntelliSense in VSCode for Python is powered by Pylance, not the base Python extension. This distinction matters when something is not working – the fix is almost always in Pylance settings, not in the Python extension itself.

Pylance uses Microsoft’s Pyright static type checking engine under the hood, combined with type stubs to deliver fast and accurate completions. The accuracy of suggestions depends directly on whether type information is available for the packages you are using.

Language Server Modes

Pylance ships with three language server modes, added in the October 2024 release:

  • light – minimal resource use, reduced IntelliSense features
  • default – balanced performance and features (standard setting)
  • full – complete IntelliSense range, resource-intensive on large codebases

Set this in settings.json via "python.analysis.languageServerMode": "full". Microsoft’s own documentation notes that full mode can be resource-intensive – particularly in large codebases.

Why Third-Party Libraries Sometimes Have Poor Autocomplete

Missing type stubs. Full stop.

Libraries like NumPy, pandas, and requests ship their own stubs or have them in the typeshed repository – so autocomplete works well. Less popular packages often have no stubs at all, which means Pylance falls back to inferred types or gives up entirely.

Fix this by installing stub packages manually:

  • pip install pandas-stubs
  • pip install types-requests
  • Search PyPI for types-[packagename] – many exist

For packages with no stubs available, you can set "python.analysis.typeCheckingMode": "off" per file or suppress specific warnings. Not ideal, but practical.

Linting and Formatting Python in VSCode

maxresdefault How to Set Up VSCode for Python Development

These two things are not the same. Linting finds code quality issues – unused variables, undefined names, style violations. Formatting changes how your code looks – indentation, line length, quote style. You need both.

A surprising number of developers I have seen set up formatting but skip linting entirely, then wonder why their code has subtle issues that tests don’t catch.

Setting Up Ruff as Combined Linter and Formatter

Ruff handles both jobs in one extension. It is written in Rust, which is why it runs noticeably faster than Python-based alternatives. For most projects, this is the right starting point.

Install the Ruff extension from the marketplace, then add this to your settings.json:

"[python]": { "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true }, "ruff.lint.enable": true `

That gives you format on save plus linting – all from one tool.

Pylint vs Ruff: Which One to Use

Ruff wins on speed and simplicity. Pylint wins on depth.

Pylint catches things Ruff misses – complex type issues, certain logical errors, custom plugin checks. Teams with strict code quality requirements often run both: Ruff for day-to-day formatting and fast linting, Pylint in CI for deeper analysis.

Per-project configuration goes in pyproject.toml or a dedicated .ruff.toml file. This matters for teams where everyone needs consistent linting behavior regardless of individual editor settings.

PEP 8 compliance, line length, and ignored rules all belong in that config file – not scattered across individual settings.json files on each developer's machine.

Debugging Python in VSCode

maxresdefault How to Set Up VSCode for Python Development

The VSCode debugger for Python is genuinely good. Better than most developers give it credit for, especially after the 2024 separation of debugpy into its own dedicated extension.

The August 2024 Python Debugger release introduced inline variable values – variable states appear directly in the editor next to the code line during a session, without hovering or switching to the variables panel. Small change, real quality-of-life improvement.

Setting Up Launch Configurations

Debugging without a launch.json works for simple scripts. For anything more complex – Flask apps, Django, test runners – you need one.

Create it via Run > Add Configuration from the menu, or drop a .vscode/launch.json manually. A basic Python script config looks like:

 { "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] } 

For Django, add “django”: true to the config and point program to manage.py. Flask needs “env”: {“FLASKAPP”: “app.py”}.

Debugging Jupyter Notebooks in VSCode

Notebook debugging in VSCode works differently from script debugging. You run cells interactively and inspect variable states inline – the Variables panel shows the current state of every object in memory after each cell execution.

Key differences from script debugging:

  • No launch.json needed for notebooks
  • Breakpoints work inside cells, but the call stack is cell-scoped
  • Kernel restarts clear all variables – worth remembering mid-debug

For Django and Flask debugging, the code review process benefits from having breakpoints set at request handler entry points – it makes tracing request flows much easier than reading logs.

Remote debugging with debugpy works by attaching VSCode to a running Python process. This is useful for debugging containerized Python apps – you expose the debugpy port and attach from VSCode’s Run and Debug panel.

Running and Testing Python Code in VSCode

maxresdefault How to Set Up VSCode for Python Development

Running a Python file in VSCode is straightforward. Click the Run button in the top-right corner or press F5. The integrated terminal handles output. Most developers stick to the terminal for scripts and use the Testing sidebar for anything structured.

53% of VSCode users actively use the editor’s Jupyter support, compared to 37% for PyCharm users and 33% for IntelliJ IDEA users, according to the JetBrains Python Developers Survey 2024.

Setting Up pytest in VSCode

Test discovery is automatic once pytest is configured. VSCode watches for changes to Python files and refreshes the test list without any manual triggers.

Steps to get pytest running in the Testing sidebar:

  • Open Command Palette, run Python: Configure Tests
  • Select pytest from the framework list
  • Point VSCode to the folder containing your tests
  • Enable test adapter: add “python.experiments.optInto”: [“pythonTestAdapter”] to settings.json

The minimum supported pytest version for the Python extension is 7.0.0, per Microsoft’s official documentation. Older versions will not work with the test discovery UI.

Code Coverage Inside VSCode

Test coverage support landed in the October 2024 release of the Python extension. Results appear in a dedicated Test Coverage sub-tab in the Testing panel.

Coverage setup: Install pytest-cov, then run tests using the “Run with coverage” option from the Testing sidebar. Line-level and branch coverage both display inline in the editor after the run completes.

For unit testing, VSCode supports both pytest and unittest out of the box. If both are enabled in settings, the extension defaults to pytest – worth knowing if you are migrating from a unittest codebase and seeing unexpected behavior.

Running vs. Debugging Tests

Running a test executes it and shows pass/fail in the sidebar. Debugging a test pauses at breakpoints so you can inspect state.

Right-click any test in the Testing panel to get both options. The debug configuration for tests uses a separate launch.json entry – if you are using pytest-cov, add PYTESTADDOPTS: “–no-cov” to the env block to prevent coverage from interfering with the debugger attach process.

VSCode Settings for Python Development

maxresdefault How to Set Up VSCode for Python Development

Most Python developers treat settings.json as an afterthought. Bad idea. The right workspace settings cut setup time for new team members significantly and keep formatting, linting, and interpreter behavior consistent across machines.

Django teams that commit .vscode/settings.json to their repo report fewer onboarding issues – new contributors open the project and get the same formatter, linter, and interpreter rules without any manual configuration.

Key Settings Every Python Developer Needs

python.defaultInterpreterPath: Sets the fallback Python binary. Useful on machines with multiple Python versions installed.

editor.formatOnSave + editor.defaultFormatter: One line in settings.json – stops the “I forgot to format” problem entirely.

editor.rulers: Add [79, 120] to show PEP 8 line length guides visually in the editor. Small thing, weirdly useful.

python.analysis.typeCheckingMode: Set to basic for most projects, strict for codebases where type hints are enforced across the board.

Workspace vs. User Settings

User settings apply globally across every project. Workspace settings live in .vscode/settings.json and override user settings per project.

The right split for most teams:

SettingWhere it goes
Formatter choice (Ruff, Black)Workspace
Linting rulesWorkspace
Default interpreter pathUser
Theme, font size, keybindingsUser
editor.rulersWorkspace

Committing .vscode/settings.json is worth it for team projects. Keep .vscode/launch.json out of version control if it contains machine-specific paths – or use ${workspaceFolder} variables to make it portable.

Settings That Affect Python Performance

python.analysis.languageServerMode: Switch to light on older machines or very large codebases where Pylance is slowing things down.

The VSCode settings system supports JSON with comments (JSONC), so you can add notes explaining why specific rules are set the way they are. Teams skip this and then spend 20 minutes figuring out why python.analysis.diagnosticSeverityOverrides silences a specific warning.

Using Jupyter Notebooks in VSCode

maxresdefault How to Set Up VSCode for Python Development

The Jupyter extension brings the full notebook experience into VSCode without a browser. Among VSCode users who work with Python for data science, 53% use the built-in Jupyter support rather than switching to JupyterLab or Google Colab, per JetBrains’ 2024 Python survey.

For exploratory data analysis, the experience is genuinely good. Pandas DataFrames render in the built-in Data Viewer. Variable states persist between cells. The kernel selection is handled by the same interpreter system as the rest of VSCode.

What the Jupyter Extension Actually Gives You

Native .ipynb support: Open, run, and edit notebook files directly – no browser, no Jupyter server running separately in a terminal.

Variable explorer: Inspect the current state of every object in memory after each cell. Especially useful when working with NumPy arrays or pandas DataFrames during data cleaning.

Export options: Convert notebooks to Python scripts, HTML, or PDF from the Command Palette. The “convert to Python script” option is handy when moving from exploratory work to production code.

VSCode Jupyter vs. JupyterLab

JupyterLab has a richer extension ecosystem specifically for notebooks. VSCode wins on everything else: Git integration, terminal access, Pylance-powered IntelliSense inside cells, and the ability to work in the same environment as the rest of your Python project.

FeatureVS Code JupyterJupyterLab
IntelliSense in cellsPylance-poweredBasic
Git integrationNativeRequires extension
Extension ecosystemGeneral VS CodeNotebook-specific
Variable explorerBuilt-inRequires extension
Browser requiredNoYes (local server)

The Python Developers Survey 2024 notes that 11% of VSCode Python users also use the Data Wrangler extension for cleaning tabular data directly inside VSCode without writing code.

Exporting Notebooks to Python Scripts

Use Jupyter: Export to Python Script from the Command Palette. Each cell becomes a section, with # %% markers that the Interactive Window can still run cell-by-cell.

This workflow is common in data science teams: prototype in notebooks, then extract clean functions into .py files for production. The web apps built with Django that do any ML inference usually go through exactly this pipeline before model code hits the back-end.

VSCode for Python Web Development

maxresdefault How to Set Up VSCode for Python Development

Python is the dominant language for back-end development in web projects, and VSCode handles both Django and Flask setups well. The April 2024 Python extension release added automatic detection of manage.py and app.py startup files when creating debug configurations – reducing the manual config work that used to trip people up.

The March 2024 release added autoStartBrowser: true support for launch configs, so VSCode now opens the browser automatically when you start the Django or Flask debugger. Small quality-of-life fix, but one that removes an annoying step from the dev loop.

Django in VSCode

The Python Debugger extension auto-detects manage.py in your workspace when generating a launch config. Pick “Django” from the debug configuration menu and it sets up the correct entry point.

Extensions that actually help for Django work:

  • Django (batisteo.vscode-django) – syntax highlighting and Go to Definition in templates
  • DjLint – linting and formatting for Django HTML templates
  • Python Dotenv – loads .env files into the workspace environment

Committing a .vscode/settings.json with “[django-html]”: { “editor.defaultFormatter”: “monosans.djlint” } keeps template formatting consistent for teams without any per-developer setup.

Flask in VSCode

Flask launch configs look for wsgi.py, app.py, or init.py files containing a Flask app declaration. If VSCode finds one, it pre-fills the config automatically.

Minimal Flask launch.json entry:

 { "name": "Python Debugger: Flask", "type": "debugpy", "request": "launch", "module": "flask", "env": { "FLASKAPP": "app.py", "FLASKDEBUG": "1" }, "args": ["run"], "jinja": true, "autoStartBrowser": true } 

The “jinja”: true flag activates Jinja2 template debugging – breakpoints inside templates actually work with this set.

Environment Variables and Docker

For .env management: Set “python.envFile”: “${workspaceFolder}/.env” in workspace settings. VSCode loads the file automatically at startup – no need for the python-dotenv package at runtime during development.

For containerized Python web apps, the containerization workflow pairs well with VSCode’s Remote extension, which lets you attach directly to a running container and debug inside it as if the code were local. The production environment parity this gives you is hard to replicate with any other editor setup.

FAQ on How To Set Up VSCode for Python Development

Does VSCode work well for Python development out of the box?

Not really. You get basic file editing, but without the Python extension by Microsoft, there’s no IntelliSense, no linter, no debugger. It takes maybe five minutes to get properly set up, but those five minutes matter.

Which Python extension should I install first?

Install the official Pylance extension. It handles autocomplete, type checking, and code navigation. Pylint and Black formatter come after, but Pylance is where you start.

How do I select the right Python interpreter in VSCode?

Press Ctrl+Shift+P, type “Python: Select Interpreter,” and pick your version. If you’re using a virtual environment, activate it first so VSCode picks up the correct Python path.

Do I need a virtual environment for every project?

Yes. Using venv or conda keeps dependencies isolated per project. Without it, packages bleed across projects and things break in ways that are genuinely painful to debug.

How do I set up linting in VSCode?

Open settings.json and set "python.linting.enabled": true. Then install Flake8 or Pylint via pip. VSCode will underline issues directly in the editor once the linting configuration is active.

What’s the best way to format Python code automatically?

Use Black formatter. Install it with pip, then set "editor.formatOnSave": true in your workspace settings. Pair it with isort to keep imports clean. Zero manual formatting after that.

How do I run and debug Python scripts inside VSCode?

Open the script, press F5. VSCode will ask you to configure launch.json the first time. Choose “Python File” and it runs. Add breakpoints by clicking the gutter next to any line number.

Why is my Python autocomplete not working in VSCode?

Usually a wrong interpreter selection or Pylance not installed. Check your Python interpreter in the status bar at the bottom. Reloading the window with Ctrl+Shift+P → “Reload Window” fixes it most of the time.

Can I use Jupyter Notebooks inside VSCode?

Yes. Install the Jupyter extension, open any .ipynb file, and the interactive window loads directly in the editor. It pulls from whichever Python virtual environment you’ve selected.

How do I configure VSCode for a Django or Flask project?

Set up a virtual environment, install your framework, then configure launch.json with the right entry point. For Django, set "program": "${workspaceFolder}/manage.py" with "args": ["runserver"]. Same idea for Flask with its app file.

Conclusion

This conclusion is for an article presenting VSCode as a capable Python development environment – one that rewards the time you put into configuring it properly.

Get the interpreter selection right, set up Pylance with the correct language server mode, and add Ruff for linting and formatting. Everything else follows from that foundation.

Pytest test discovery, Jupyter notebook support, debugpy breakpoints, and Django or Flask launch configurations all work reliably once the workspace settings are clean.

If you are choosing between editors, the VSCode vs IntelliJ and Cursor vs VSCode comparisons are worth reading. For most Python developers, Visual Studio Code hits the right balance of speed, flexibility, and tooling depth.

50218a090dd169a5399b03ee399b27df17d94bb940d98ae3f8daff6c978743c5?s=250&d=mm&r=g How to Set Up VSCode for Python Development

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.