Visual Studio Code Configuration for Python, Data Science and Machine Learning

Last updated 20 / Mar / 2026

This post is a living document: it reflects my current VS Code configuration, and it is updated over time as I change my settings, extensions, or tools.

Introduction

Visual Studio Code (VS Code) is a free, lightweight, and highly extensible source code editor developed by Microsoft. It is one of the most popular editors for software development thanks to its wide ecosystem of extensions and its customization capabilities.

However, installing VS Code is not enough: to get the most out of it when working with Python, Data Science and Machine Learning, it needs to be configured properly. A good configuration allows you to:

  • Code quality: enable linters and automatic formatters that detect errors and maintain a consistent code style.
  • Unit testing: integrate the test runner directly in the editor to run tests and see results without leaving VS Code.
  • Debugging: configure the debugger to be able to inspect the program state step by step with the correct environment variables.

VS Code configurations are stored in the .vscode/ folder at the root of the project. Having these files versioned alongside the code ensures that the entire team (or any future collaborator) uses exactly the same configuration.


General configuration — settings.json

The settings.json file contains the editor preferences for the project. These settings override the user’s global preferences when working inside the project.

{
  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": "explicit",
      "source.organizeImports": "explicit"
    },
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.rulers": [100]
  },
  "notebook.formatOnSave.enabled": true,
  "notebook.defaultFormatter": "charliermarsh.ruff",
  "notebook.codeActionsOnSave": {
      "notebook.source.fixAll": "explicit",
      "notebook.source.organizeImports": "explicit"
  },
  "[markdown]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll.markdownlint": "explicit"
    }
  },
  "files.exclude": {
    "**/__pycache__": true
  },
  "python.languageServer": "None",
  "editor.formatOnPaste": true,
  "notebook.lineNumbers": "on",
  "editor.inlineSuggest.enabled": true,
  "editor.formatOnType": true,
  "git.autofetch": true,
  "python.terminal.activateEnvInCurrentTerminal": true,
  "python.testing.pytestArgs": [
    "tests"
  ],
  "python.testing.unittestEnabled": false,
  "python.testing.pytestEnabled": true,
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
  "markdownlint.config": {
    "MD007": {"indent": 4}
  },
  "ruff.configuration": "--config=.code_quality/ruff.toml",
  "ruff.format.preview": true,
  "mypy-type-checker.args": [
    "--config-file=.code_quality/mypy.ini"
  ]
}

Explanation of each section

[python] — Configuration for Python files

"[python]": {
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit",
    "source.organizeImports": "explicit"
  },
  "editor.defaultFormatter": "charliermarsh.ruff",
  "editor.rulers": [100]
}
  • editor.formatOnSave: automatically formats the file every time it is saved.
  • source.fixAll: applies all available automatic fixes on save (removes unused imports, fixes style errors, etc.).
  • source.organizeImports: sorts and groups imports following Python conventions (stdlib, third-party, local).
  • editor.defaultFormatter: uses Ruff as the default formatter. Ruff is an extremely fast linter and formatter written in Rust that replaces Flake8, isort, Black, and others.
  • editor.rulers: displays a vertical line at column 100 to indicate the recommended line length limit.

Jupyter Notebooks configuration

"notebook.formatOnSave.enabled": true,
"notebook.defaultFormatter": "charliermarsh.ruff",
"notebook.codeActionsOnSave": {
    "notebook.source.fixAll": "explicit",
    "notebook.source.organizeImports": "explicit"
}

Applies the same formatting and import organization rules as in .py files, but inside Jupyter notebooks (.ipynb). This maintains code quality also during the exploratory phase.


[markdown] — Configuration for Markdown files

"[markdown]": {
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.markdownlint": "explicit"
  }
}
  • Enables automatic formatting when saving .md files.
  • Applies markdownlint corrections on save, ensuring that documentation follows Markdown style conventions.

files.exclude — Hide unnecessary files

"files.exclude": {
  "**/__pycache__": true
}

Hides __pycache__ folders in the VS Code file explorer. These folders contain compiled Python bytecode and are not relevant for development.


python.languageServer — Language server

"python.languageServer": "None"

Disables the built-in Python language server (Pylance). "None" is used when you prefer to rely on Ruff and Mypy for static analysis, avoiding duplicate diagnostics or conflicts between tools.


General editor configuration

"editor.formatOnPaste": true,
"editor.inlineSuggest.enabled": true,
"editor.formatOnType": true,
"notebook.lineNumbers": "on"
  • editor.formatOnPaste: automatically formats pasted code to match the project’s style.
  • editor.inlineSuggest.enabled: enables inline autocomplete suggestions (like GitHub Copilot or other suggestion sources).
  • editor.formatOnType: formats the code as you type.
  • notebook.lineNumbers: shows line numbers in Jupyter notebooks.

git.autofetch — Automatic Git synchronization

"git.autofetch": true

VS Code automatically fetches remote Git changes in the background, keeping the repository state up to date without needing to run git fetch manually.


python.terminal — Automatic virtual environment activation

"python.terminal.activateEnvInCurrentTerminal": true

Automatically activates the Python virtual environment (.venv) when an integrated terminal is opened in VS Code. This avoids having to activate the environment manually each time.


pytest configuration

"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
  • pytestEnabled: enables pytest as the testing framework.
  • unittestEnabled: disables the unittest runner to avoid conflicts.
  • pytestArgs: tells VS Code to look for tests in the tests/ folder.

[jsonc] — Formatter for JSON files with comments

"[jsonc]": {
  "editor.defaultFormatter": "vscode.json-language-features"
}

Uses VS Code’s native JSON formatter for .jsonc (JSON with Comments) files, such as settings.json or launch.json themselves.


python.defaultInterpreterPath — Python interpreter

"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python"

Points to the Python interpreter inside the project’s virtual environment (.venv), ensuring that VS Code always uses the correct environment with the project’s dependencies installed.


Markdownlint configuration

"markdownlint.config": {
  "MD007": {"indent": 4}
}

Customizes markdownlint rule MD007 to require 4-space indentation in nested Markdown lists.


Ruff configuration

"ruff.configuration": "--config=.code_quality/ruff.toml",
"ruff.format.preview": true
  • ruff.configuration: tells the Ruff extension where to find its configuration file (.code_quality/ruff.toml), instead of looking in the project root.
  • ruff.format.preview: enables formatting rules in preview mode (new features that are not yet stable).

Mypy configuration

"mypy-type-checker.args": [
  "--config-file=.code_quality/mypy.ini"
]

Tells the Mypy extension where to find its configuration file (.code_quality/mypy.ini). Mypy is the Python static type checker that verifies type annotations.


Debugging configuration — launch.json

The launch.json file defines the debugging configurations that appear in the “Run and Debug” panel of VS Code.

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "debugpy",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "cwd": "${workspaceFolder}",
      "env": {
        "PYTHONPATH": "${cwd}",
        "VERBOSITY": "DEBUG"
      }
    }
  ]
}

Explanation

  • version: version of the launch.json schema. Version 0.2.0 is the current standard.
  • name: name shown in the debug configuration selector (Python: Current File).
  • type: uses debugpy, the official Python debugger for VS Code.
  • request: launch indicates that VS Code will launch the program (as opposed to attach, which connects to an already running process).
  • program: ${file} runs the Python file that is currently open in the editor.
  • console: integratedTerminal displays the output in VS Code’s integrated terminal, allowing interaction with the program if needed.
  • cwd: sets the working directory to the project root (${workspaceFolder}), avoiding issues with relative paths.
  • env: defines environment variables for the debug session:
    • PYTHONPATH: points to the project root so Python can correctly import local modules.
    • VERBOSITY: sets the logging level to DEBUG to get detailed information during debugging.

The extensions.json file contains a list of recommended extensions for the project. When someone opens the project in VS Code, the editor automatically suggests installing them.

{
  "recommendations": [
    "alefragnani.project-manager",
    "bierner.emojisense",
    "charliermarsh.ruff",
    "davidanson.vscode-markdownlint",
    "editorconfig.editorconfig",
    "github.copilot-chat",
    "github.vscode-github-actions",
    "GitHub.vscode-pull-request-github",
    "KevinRose.vsc-python-indent",
    "mechatroner.rainbow-csv",
    "ms-python.mypy-type-checker",
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-toolsai.jupyter",
    "oderwat.indent-rainbow",
    "redhat.vscode-yaml",
    "streetsidesoftware.code-spell-checker",
    "tamasfe.even-better-toml",
    "usernamehw.errorlens",
    "vivaxy.vscode-conventional-commits",
    "vscode-icons-team.vscode-icons"
  ]
}

Description of each extension

ExtensionDescription
Project Manager (alefragnani.project-manager)Allows saving and quickly switching between projects without having to navigate the file system.
Emojisense (bierner.emojisense)Autocomplete and preview for emojis in text and code files.
Ruff (charliermarsh.ruff)Ultra-fast linter and formatter for Python. Replaces Flake8, isort, pyupgrade, Black and others in a single tool.
markdownlint (davidanson.vscode-markdownlint)Linting of Markdown files using configurable rules to maintain quality documentation.
EditorConfig (editorconfig.editorconfig)Applies style settings (indentation, encoding, line endings) defined in an .editorconfig file, ensuring consistency across editors and operating systems.
GitHub Copilot Chat (github.copilot-chat)GitHub Copilot AI assistant with a chat interface for asking questions about code, generating code, explaining functions, and more.
GitHub Actions (github.vscode-github-actions)Visualization and editing of GitHub Actions workflows directly from VS Code, with autocomplete and validation.
GitHub Pull Requests (GitHub.vscode-pull-request-github)GitHub Pull Request management without leaving VS Code: create, review, comment on, and merge PRs.
Python Indent (KevinRose.vsc-python-indent)Improves the Enter key behavior in Python to correctly indent within structures such as lists, dictionaries, and functions.
Rainbow CSV (mechatroner.rainbow-csv)Colorizes the columns of CSV files with different colors to make reading and error detection easier.
Mypy Type Checker (ms-python.mypy-type-checker)Integrates Mypy in VS Code to verify Python type annotations and detect type errors during development.
Python (ms-python.python)Official Python extension for VS Code. Provides base support: IntelliSense, script execution, virtual environment management, and more.
Pylance (ms-python.vscode-pylance)High-speed Python language server with advanced IntelliSense, type inference, and code navigation.
Jupyter (ms-toolsai.jupyter)Full Jupyter Notebook support in VS Code: create, edit and run cells, manage kernels, and visualize results.
Indent Rainbow (oderwat.indent-rainbow)Colorizes indentation levels with different colors to make reading code with multiple levels of nesting easier.
YAML (redhat.vscode-yaml)Full YAML support with schema validation, autocomplete, and formatting. Very useful for CI/CD configuration files.
Code Spell Checker (streetsidesoftware.code-spell-checker)Spell checker for code and comments. Detects typos in English (and other languages with additional dictionaries).
Even Better TOML (tamasfe.even-better-toml)Full TOML file support with syntax highlighting, validation, and autocomplete. Essential for projects using pyproject.toml.
Error Lens (usernamehw.errorlens)Displays errors, warnings, and diagnostics directly on the line of code where they occur, without needing to hover over them.
Conventional Commits (vivaxy.vscode-conventional-commits)Assistant for writing commit messages following the Conventional Commits specification, with autocomplete for type, scope, and description.
vscode-icons (vscode-icons-team.vscode-icons)Adds file and folder icons to the VS Code explorer to visually identify file types quickly.
Next