VSCode

How to Set Up VSCode for Python Development

How to Set Up VSCode for Python Development

The Python extension adds language support to VS Code, but it doesn’t bundle Python. An interpreter has to be on the machine first, and once the extension is in, the last piece is selecting a virtual environment as the workspace interpreter.

VS Code was the most used development environment in the Stack Overflow Developer Survey 2026, at 70.9% of respondents to that question, down from 75.9% in 2025. Plenty of people are in that group, and every one of them still has to install an interpreter separately.

Mac users hit a snag early. Microsoft’s documentation does not support the system Python, so the interpreter has to come from a package manager such as Homebrew.

What Does VSCode Need Before It Can Run Python Code?

YouTube player

The editor and an interpreter. The Python extension adds language support to VS Code but does not include Python itself, which is the part people tend to miss.

Microsoft’s setup guide splits the stack in a way that clears this up. VS Code is the editor where you write and organize code, and the interpreter is the program that runs it. The extension sits in between and adds language support inside the editor.

The extension supports only actively supported Python versions, so the version you pick matters.

According to the Python Developer’s Guide, Python 3.9 reached end of life on 2025-10-31 and 3.10 on 2026-10-01. Python 3.15 shipped on 2026-10-09, and 3.14 is supported through 2030-10. Those are the dates as of November 2026.

I’d go with 3.14 for a fresh project. 3.15 is barely six weeks old, so check it against your dependencies before committing to it.

On Windows, the python.org installer works, and the Microsoft Store is the way to go when you lack admin access. Verify with py -3 –version.

On macOS, install through Homebrew (brew install python3), since the system Python isn’t supported. python3 –version confirms it worked.

Linux already ships a built-in Python 3, and the same python3 –version check applies.

Run the version check in the integrated terminal, so it uses the same shell the editor does. Opening a terminal takes a few seconds, and there’s a short guide on opening the terminal in VSCode if you need it.

Installing extra packages on Linux requires pip first, and the tutorial points to get-pip.py for that. Anyone on Ubuntu can follow a separate guide on installing VSCode on Ubuntu.

The official tutorial starts VS Code in a workspace folder before anything else, and the .venv folder you create in the next steps ends up inside it.

Which Extensions Does Python Development in VSCode Require?

YouTube player

Just the Python extension (ms-python.python) from Microsoft. Pylance and the Python Debugger come with it by default, along with the Python Environments extension.

Core extensions

  • The Python extension (ms-python.python) is the entry point, and the only one you actually search for.
  • Pylance (ms-python.vscode-pylance) handles code completion, signature help, auto-imports and as-you-type diagnostics.
  • Python Debugger (ms-python.debugpy) installs automatically with the Python extension. It’s built on debugpy.
  • Python Environments (ms-python.vscode-python-envs) manages environments. Its README marks it as new.

The Marketplace listing shows more than 246 million installs for the Python extension, and more than 212 million for Pylance. Nobody assembles this stack by hand.

The bundled pieces are optional. You can disable or uninstall any of them, but each removal costs you features. Take out Pylance and the completions go with it.

The Python Environments extension is the one that trips people up. It puts environment creation and package installs behind one UI, and interpreter switching lives there too.

Whether it is active depends on the python.useEnvironmentsExtension setting. Users without that setting may be opted in at random during rollout, which explains why one machine shows an Environment Managers view and a colleague’s does not. The VS Code docs do not say whether the extension is preview or generally available.

Optional extensions

Install the Jupyter extension (ms-toolsai.jupyter) only if you work in .ipynb notebooks.

Linters and formatters (Ruff, Pylint, Flake8, Black) are separate Marketplace installs, covered in the linting and formatting section below. Search for them by name in the Extensions view, and check the publisher before installing.

A wider rundown of VS Code extensions beyond Python sits in its own guide.

venv or conda: Which Environment Manager Fits the Project?

For a pure Python project, venv is enough. Conda earns its place only when non-Python binaries are involved or the project already lives in a conda workflow.

VS Code finds venv, System Python, Conda, Pyenv, Poetry and Pipenv environments automatically, but it can only create venv and conda ones.

ManagerFound by VS CodeCreated in VS CodeBest fit
venvYesYesPure Python projects
condaYesYesProjects with non-Python binaries, environment.yml
Poetry, PipenvYesNoProjects already managed by these tools
PyenvYesNoSwitching between Python versions

The last two rows are where people get stuck. A Poetry or Pipenv environment shows up in the interpreter list, but VS Code won’t build one for you. Create it in the terminal first, then select it.

uv is the odd entry. The environments page uses uv automatically for venv creation and package installs when it is installed (python-envs.alwaysUseUv, default true).

That same page names uv as supported in its introduction but leaves it out of both the discovery and creation tables. Think of uv as a speed-up under venv rather than a fifth manager.

I’d skip conda unless a dependency forces it, since on a pure Python project it just adds a second package ecosystem for no gain. The trade-offs outside the editor get more room in a longer comparison of venv, conda and Poetry.

How to Create a Virtual Environment and Select the Interpreter in VSCode

Run Python: Create Environment from the Command Palette, choose Venv, and pick a base interpreter. A .venv folder then appears in the workspace.

  1. Open the project folder as the workspace.
  2. Open the Command Palette (F1, or Ctrl+Shift+P, Cmd+Shift+P on macOS) and run Python: Create Environment.
  3. Select Venv, then the base interpreter. The custom flow also asks for a Python version and a name, and offers to install dependencies from requirements.txt, pyproject.toml or environment.yml.
  4. Check the interpreter shown in the status bar. If it is wrong, run Python: Select Interpreter.
  5. Install packages into the new environment, for example python -m pip install requests.
  6. Click Run Python File. The terminal that opens activates the selected interpreter automatically.

The Environment Managers view in the Python sidebar has a + button for Quick Create, which skips the prompts and uses default settings. It suits throwaway projects.

If the status bar keeps showing the wrong environment, the walkthrough on changing the Python interpreter in VSCode covers the other routes.

On terminal activation, the python-envs.terminal.autoActivationType setting defaults to command, with shellStartup and off as the other options. Restart open terminals after changing it.

The older python.terminal.activateEnvironment setting (default true) is superseded once the newer one is configured.

When activation fails in a specific shell, a separate guide shows how to activate a venv in VSCode by hand.

How Does Pylance Power IntelliSense, and Which Type Checking Mode Should You Use?

YouTube player

Out of the box, VS Code uses Pylance as the Python language server. It’s based on Microsoft’s Pyright and installs alongside the Python extension. Autocomplete and signature help while you type come from it, and so do the warnings about imports it can’t resolve.

Auto imports are off until you set python.analysis.autoImportCompletions to true, which surprises people. Type checking is off by default too, more on that below.

Pylance’s default language server mode aims for sufficient functionality on most machines without overloading the system. A light mode (python.analysis.languageServerMode set to light) trims features further for low-memory setups.

Plenty of people lean on it for type checking. The Typed Python Survey 2025 (Meta, JetBrains and community contributors) found VS Code’s default, Pylance/Pyright, is the most popular type checking option within IDEs.

python.analysis.typeCheckingMode defaults to off. The documentation disagrees on the allowed values. The Pylance Marketplace page lists off, basic, standard and strict, while the VS Code settings reference lists only off, basic and strict. Check the dropdown in your own Settings UI before copying a value into settings.json.

For legacy and untyped code, off or basic is the sensible place to stay. Strict only pays off when the codebase is already annotated, since it reports far more issues on code that isn’t.

mypy is a separate route. It runs through its own extension (vscode-mypy), independent of Pylance, so the two checkers can disagree on the same file.

How to Set Up Linting and Formatting for Python in VSCode

Ruff does linting and formatting in a single extension, and sorts imports too. Pylint or Flake8 plus Black Formatter only make sense when the project already depends on them.

The Python extension itself only detects syntax errors by default, so stylistic checks need a linter extension. Microsoft’s formatting page says linting and formatting support has migrated to tools extensions.

ToolRoleListed in VS Code docs as
RuffLinter, formatter, import sortingCommunity extension
PylintLinterMicrosoft extension
Flake8LinterMicrosoft extension
Black FormatterFormatterMicrosoft extension

Once installed, a linter runs when a Python file is opened or saved and reports to the Problems panel and the editor. A primer on what linting does in programming helps if the term is new.

Choosing a linter

I’d pick one tool over three. Ruff’s extension gives diagnostics, quick fixes, a Fix all action, Black-compatible formatting and isort-compatible Organize Imports, per its README.

It also ships its own binary (ruff==0.17.3 at the time of the November 2026 README). If no Ruff executable exists in the active Python environment, the extension checks PATH before falling back to the bundled one.

Running Ruff next to the isort extension puts two tools on import sorting, and the fix is setting ruff.organizeImports to false.

Old tutorials cause trouble too. The python.linting and python.formatting settings are no longer supported, and the docs advise deleting them.

Setting up format on save

  1. Install the formatter extension: Black Formatter (ms-python.black-formatter) or Ruff (charliermarsh.ruff).
  2. Run Preferences: Open User Settings (JSON) from the Command Palette, or the Workspace variant to scope it to one project.
  3. Inside the [python] block, set editor.defaultFormatter to the extension ID you installed.
  4. In the same block, set editor.formatOnSave to true.
  5. For import sorting, add editor.codeActionsOnSave with source.organizeImports.ruff set to explicit. Add source.fixAll.ruff the same way to apply Ruff’s safe fixes on save.

Ruff skips unsafe fixes by default, and the scoped actions run only Ruff’s own code actions on save.

Black Formatter has a gap. It does not support Format Selection, so Microsoft suggests editor.formatOnPaste set to false and editor.formatOnSaveMode set to file. The general routine for autoformatting in VSCode applies to other languages too.

How to Debug Python in VSCode with launch.json

Open the Run and Debug view and click Run and Debug, or pick Python Debugger: Debug Python File from the run button’s dropdown. No launch.json is needed for a single script.

Pressing F5 with no configuration opens the configuration menu but does not create a launch.json file. The file appears only when you choose a configuration to save.

Python File is the default for a simple script and runs whichever script you choose. Attach connects to a running process, say one started with debugpy’s –listen option. Django runs manage.py with runserver and turns on template debugging, and Flask uses the module property with flask and sets FLASK_APP.

FastAPI shows up differently. Show all automatic debug configurations builds Flask and Django setups from your project structure, and FastAPI ones too, though the docs give no sample FastAPI config.

launch.json lives in the .vscode folder, so the code must sit in an opened folder. A step-by-step walkthrough on debugging Python in VSCode covers the first session click by click.

Conditional breakpoints take an expression or a hit count such as >5. Logpoints print a message without stopping the program, and debugpy.breakpoint() in code stops execution from inside the script.

justMyCode defaults to true, which keeps stepping inside your own code. Set it to false to step into standard library functions.

Use “debugpy” as the type in launch.json, because the older “python” value is deprecated. Snippets copied from older tutorials still carry the old value, so it’s easy to paste the wrong one.

The debugger uses the interpreter selected for the workspace, and the python property in launch.json overrides it. A debug session that cannot import your packages usually means the wrong environment is selected, not a broken launch.json.

How to Configure Testing with pytest or unittest

Open the Test Explorer (the beaker icon), select Configure Python Tests, then choose a framework and the folder holding your tests. unittest also asks for a file glob pattern.

Nothing runs until you do this. Both python.testing.pytestEnabled and python.testing.unittestEnabled default to false.

pytest finds files named test_*.py or *_test.py in the current folder and every subfolder, and the minimum supported version is 7.0.0.

unittest works differently. It ships with Python, so there is nothing to install, but it only looks in the top-level project folder for .py files with “test” in the name, and those files must be importable modules or packages.

For a new project I’d pick pytest. unittest makes sense when the codebase already uses it or the dependency list has to stay empty.

If both frameworks are turned on, only pytest runs. Switch one off before wondering why unittest cases disappear.

Discovery then runs by itself. It starts automatically once a framework is enabled, and Test: Refresh Tests forces a rerun. autoTestDiscoverOnSaveEnabled defaults to true, so saved changes to .py files retrigger discovery.

If tests in a subfolder go missing, add an empty __init__.py so the folder is importable. When pytest isn’t in the environment, the extension tries to install it in the background, but tests only use the activated environment. And if a discovery error banner shows up, check the Python panel in the Output view for the full message, which names a syntax error or missing framework.

The dedicated guide on running pytest in VSCode goes deeper on arguments and fixtures.

Where Should Python Settings Live in VSCode?

Workspace settings are specific to a project and override user settings. Keep personal preferences in user settings and anything the project depends on in .vscode/settings.json.

The VS Code documentation gives these reference values as of November 2026.

  • 11 settings scopes in precedence order, from default settings to administrator policy
  • 4 interpreter sources in priority order, from pythonProjects[] down to auto-discovery
  • python.defaultInterpreterPath defaults to “python”
  • The default environment search pattern is ./**/.venv
  • python.analysis.extraPaths defaults to an empty collection

User and workspace settings

Objects merge across scopes, while primitive and array values are overridden. A workspace list of extraPaths therefore replaces the user one instead of adding to it.

Language blocks keyed by [python] work in either scope, though some settings are picky about where they go. python-envs.workspaceSearchPaths belongs at workspace level, not user level.

Reaching the file takes one command. Preferences: Open Workspace Settings (JSON) opens the project file, and a separate guide covers opening settings.json in VSCode by other routes.

VS Code picks the interpreter in this order.

  1. pythonProjects[], when a project is configured for the path
  2. defaultEnvManager, only if you set it explicitly
  3. python.defaultInterpreterPath, a legacy fallback that still works
  4. Auto-discovery, workspace-local environments first, then global interpreters

WSL and Dev Containers

For WSL, run code . from a WSL terminal, or use WSL: Connect to WSL from the Command Palette. Extensions and terminals run inside WSL, so the interpreter you select is the Linux one. Local extensions that must run remotely appear dimmed, with an Install button.

The Dev Containers extension (ms-vscode-remote.remote-containers) opens a folder inside a container. devcontainer.json lives in .devcontainer/ (or as .devcontainer.json in the project root) and lists extension IDs under customizations.vscode.extensions. Docker has to be there too, running locally or on a remote host.

Putting ms-python.python in that array means a teammate gets the extension without installing it by hand. If containers are new to you, a short explainer on what Docker is covers the prerequisite.

Microsoft’s WSL page does not cover Python or interpreter selection, so treat the Linux-interpreter point as the consequence of where extensions run, not a documented Python rule. Both remote pages were updated in November 2026.

Why Does VSCode Report a Missing Interpreter or Unresolved Imports?

YouTube player

Usually the selected interpreter is not the environment where the package was installed. Selecting the correct interpreter is one of the documented fixes for an unresolved import, alongside installing the package and adding an extra path.

SymptomCauseFix
importResolveFailurePylance cannot find the module or its stubsInstall the package, add an extra path, or select the right interpreter
importResolveSourceFailureStubs found, package missing from selected environmentInstall it into that environment
Environment shows “(broken)”pyvenv.cfg missing or executable invalidRecreate the environment
New environment not listedDiscovery cache is staleRun Refresh All Environment Managers

The first two rows come from Pylance’s import diagnostics, and the last two from the environments troubleshooting table.

Package installs fail for a different reason. If the terminal says pip is not recognized, the walkthrough on the pip is not recognized error in VS Code covers the PATH side. Inside an activated environment, python -m pip install bypasses that lookup.

If an environment isn’t listed at all, add its location to workspaceSearchPaths or globalSearchPaths. A conda environment missing from the list means conda is not on your PATH.

Broken environments are cheaper to rebuild than to repair. Remove the folder, following a guide on how to delete a venv, then rerun Python: Create Environment.

For raw discovery output, run Python Environments: Run Python Environment Tool (PET) in Terminal and choose Find All Environments. Reach for it only after the refresh command fails.

When a linter reports nothing, check its logs and confirm an interpreter is selected for the workspace.

FAQ About VSCode for Python Development

Is VSCode a good alternative to PyCharm for Python?

For most Python work, yes. The Python extension covers IntelliSense, debugging, testing and environment management, and the Typed Python Survey 2025 (Meta, JetBrains and community contributors) found VS Code the most popular IDE among Python developers, ahead of PyCharm. The 2026 edition again had VS Code as the most selected editor or IDE, at 59.3%.

A longer breakdown of how VSCode compares with PyCharm weighs the trade-offs.

Can Python run on vscode.dev in the browser?

Only partially. The Python extension offers some support on vscode.dev, including github.dev, with partial IntelliSense for open files in the editor.

The interpreter and virtual environment steps need a local install, so use the desktop editor for the complete setup.

Does VSCode run more than one linter at once?

Yes. Pylint and Flake8 install as separate extensions, Ruff too, and several can run together.

To switch one off for a project, disable its extension in that workspace.

How do you start a new Python project in VSCode?

Create a folder, open it as the workspace, then run Python: Create Environment. InfoWorld’s January 2024 guide notes the extension had no built-in feature for scaffolding a blank Python project, and tools such as Poetry or Hatch handle that from the command line.

Microsoft also offers a Python profile template. It comes with useful extensions and settings, plus some code snippets.

Which Parts of the Python Setup Belong in Version Control?

A dependency file and .vscode/settings.json are what make a VSCode for Python development setup repeatable. The .venv folder stays out of the repository.

When a new environment is created, the extension detects requirements.txt or pyproject.toml in the workspace and installs from it, so the file rebuilds the .venv on any machine.

Commit the dependency file first, since every later step needs a working environment. Formatter and test settings in .vscode/settings.json can follow, and devcontainer.json only matters when the team needs identical tooling.

Committing settings has a cost. Workspace settings override user settings and apply to every user of the project, so a committed formatter replaces a teammate’s personal choice. Machine-specific values such as an interpreter path should stay with each developer.

Pushing these files to a remote starts with connecting VSCode to GitHub. This advice reflects the VS Code documentation as verified in November 2026.

Bogdan Sandu

Stay sharp. Ship better code.

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