1.6. VS Code
What is Visual Studio Code?
Visual Studio Code (VS Code) is a free, open-source code editor from Microsoft that has become the de-facto standard for modern software development. It combines the simplicity of a text editor with powerful Integrated Development Environment (IDE) features. Its lightweight nature, combined with a vast ecosystem of extensions, makes it an ideal choice for Python and MLOps development, where versatility and performance are key.
Why is VS Code the right choice for MLOps?
For MLOps professionals, a powerful and adaptable editor is non-negotiable. VS Code excels by providing:
- High-Performance Editing: Get intelligent code completion with IntelliSense, seamless code navigation, and immediate feedback without the heavy footprint of traditional IDEs.
- Unmatched Extensibility: The Marketplace lets you tailor your environment precisely for MLOps tasks, with extensions for Python, Docker, Kubernetes, cloud platforms, and more.
- Seamless Workflow Integration: Manage your entire workflow in one place. Use the Integrated Terminal to run experiments, Source Control to manage code with Git, and powerful Debugging Tools to troubleshoot models and pipelines.
- Remote Development: Connect to remote servers, containers, or the Windows Subsystem for Linux (WSL) as if they were local. This is critical for training models on powerful cloud instances or ensuring consistent development environments.
How do you install VS Code?
Installing VS Code is straightforward:
- Navigate to the official VS Code website.
- Download the appropriate installer for your operating system (Windows, macOS, or Linux).
- Run the installer and follow the on-screen instructions.
Where can you master VS Code?
To accelerate your learning curve, explore these excellent resources:
- Official Documentation: The definitive source for every feature.
- VS Code Tips and Tricks: A collection of shortcuts and best practices to boost your productivity.
- Microsoft Learn: Free, hands-on tutorials for various development scenarios.
- Official YouTube Channel: Visual guides and tutorials for all skill levels.
Which extensions are essential for MLOps?
A stock VS Code editor is powerful, but extensions unlock its true potential for MLOps. We've curated a list of extensions, categorized into tiers, to build a professional-grade development environment. You can install them directly from the VS Code Marketplace.
Which VS Code extensions should you install for MLOps?
This section lists the extensions you can install from VS Code Marketplace:
A Tier: The Must
- donjayamanne.python-extension-pack: ultimate pack for Python development: autoDocString, Python, Jinja, IntelliCode, Python Indent, Python Environment Manager, Django.
- donjayamanne.python-environment-manager: access and manage your Python environments (venv).
- KevinRose.vsc-python-indent: improve the default indentation for Python files.
- ms-python.mypy-type-checker: source typing for Python. Great to validate your code and communicate it should be used.
- ms-python.python: language support for Python (linting, debugging, code formating, and more).
- ms-python.vscode-pylance: enhanced language server for Python (static checker, intellicode, …).
- ms-toolsai.jupyter: extension pack for Jupyter Notebooks: Keymap, Slideshow, Notebook Renderer, and Cell Tags.
- ms-toolsai.jupyter-keymap: keybindings from Jupyter Notebooks.
- ms-toolsai.jupyter-renderers: render notebook outputs (e.g., plots).
- ms-toolsai.vscode-jupyter-cell-tags: edit cell tags in notebooks (i.e., metadata used by some plugins).
- charliermarsh.ruff: A Visual Studio Code extension for Ruff, an extremely fast Python linter and code formatter, written in Rust.
B Tier: The Great
- alefragnani.project-manager: organize, manage, and access VS Code workspaces and Git repositories.
- ms-azuretools.vscode-docker: manage and connect to Docker through VS Code.
- ms-kubernetes-tools.vscode-kubernetes-tools: everything you need to develop Kubernetes applications from VS Code.
- ms-vscode-remote.remote-containers: develop your code from a Docker container instead of your local system.
- ms-vscode-remote.remote-ssh: connect to a remote instance for editing files and developing your project.
- ms-vscode-remote.remote-ssh-edit: language support for SSH configuration files.
- ms-vscode-remote.vscode-remote-extensionpack: extension pack for remote developments: Dev Containers, Remote SSH, Remote Tunnels, WSL.
- ms-vscode.remote-explorer: view remote machines (SSH) and tunnels.
- ms-vscode.remote-repositories: remotely browse and edit git repositories.
- ms-vsliveshare.vsliveshare: edit code from your colleague computer (and vice versa). Useful for collaboration and troubleshooting.
- mutantdino.resourcemonitor: display the resource usage of your system in the status bar (CPU, RAM, …). Always useful for data projects.
- njpwerner.autodocstring: automatically generate Python docstrings from object definitions.
- redhat.vscode-yaml: YAML language support. Great file format for configuring your application.
- streetsidesoftware.code-spell-checker: highlight and fix spelling mistakes in your code.
- tamasfe.even-better-toml: TOML language support. Improve the edition of your
pyproject.toml
file. - usernamehw.errorlens: display warnings and errors next to your code (instead of a dedicated window).
- VisualStudioExptTeam.vscodeintellicode: AI-assisted development features for VS Code.
- yzhang.markdown-all-in-one: tons of feature for editing Markdown files (shortcuts, table of content, language support, …).
C Tier: The Good
- aaron-bond.better-comments: highlight comments based on a prefix (e.g., *, !, ?, TODO, …).
- bierner.markdown-mermaid: display Mermaid diagrams in Markdown. Great to share and visualize complex concepts and design decisions.
- christian-kohler.path-intellisense: autocomplete file paths on your system.
- donjayamanne.githistory: visualize your Git history (files, branches, commits, …).
- eamodio.gitlens: enhanced your git experience (e.g., git blame, code lens, …).
- GitHub.remotehub: remotely browse and edit GitHub repositories.
- github.vscode-github-actions: manage GitHub Actions workflows from VS Code.
- GitHub.vscode-pull-request-github: manage GitHub Pull Requests from VS Code.
- Gruntfuggly.todo-tree: view all TODO, FIXME, and other annotations from a Tab.
- IBM.output-colorizer: syntax highlighting for log files.
- jebbs.plantuml: create UML diagrams to document your project.
- mechatroner.rainbow-csv: colorize the columns of CSV files to improve their readability.
- mhutchie.git-graph: view and edit your git graph (tags, branches, stashes, …).
- mikestead.dotenv: syntax highlighting for dotenv files (i.e., contain the environment variables of your program).
- ms-vscode.live-server: host a local server for web development.
- oderwat.indent-rainbow: make code indentation more readable.
- pomdtr.excalidraw-editor: edit Excalidraw diagrams. Great to design architecture diagrams during brainstorm sessions.
- sleistner.vscode-fileutils: create, copy, move, rename, and delete files from VS Code commands.
- vsls-contrib.gistfs: manage and share code snippets on GitHub Gist.
- wayou.vscode-todo-highlight: highlight TODO, FIXME and other keywords in your comments.
- wholroyd.jinja: language support for Jinja. Popular template language for substituting variables in text files.
How should you configure VS Code for MLOps?
A well-tuned settings.json
file is the key to a productive and standardized development environment. The settings below are optimized for MLOps, emphasizing readability, automation, and seamless integration with Python tools.
To apply them, open the Command Palette (Ctrl+Shift+P
or Cmd+Shift+P
), search for Preferences: Open User Settings (JSON)
, and paste the following code. Each setting includes a comment explaining its purpose.
{
// enable Code Spell Checker by default
"cSpell.enabled": true,
// limit Code Spell Checker to markdown files
"cSpell.enabledLanguageIds": [
"markdown"
],
// use en-US language by default for Code Spell Checker
"cSpell.language": "en-US",
// don't accept completion on enter
"editor.acceptSuggestionOnEnter": "off",
// don't let the cursor blink (distracting)
"editor.cursorBlinking": "solid",
// smooth caret for smooth editing :)
"editor.cursorSmoothCaretAnimation": "on",
// always let 15 lines as a margin when you scroll
"editor.cursorSurroundingLines": 15,
// use Fira code as the main font (support ligatures)
"editor.fontFamily": "'Fira Code', monospace",
// enable programming ligature (e.g., replace -> by →)
"editor.fontLigatures": true,
// default font size, use something comfortable for your eyes!
"editor.fontSize": 14,
// format the code you copy-paste in your editor
"editor.formatOnPaste": true,
// show the completion next to your cursor
"editor.inlineSuggest.enabled": true,
// disable the minimap on the right (distracting)
"editor.minimap.enabled": false,
// disable highlighting the word under the cursor (distracting)
"editor.occurrencesHighlight": false,
// don't highlight the current line (distracting)
"editor.renderLineHighlight": "none",
// smooth scrolling for smooth developments :)
"editor.smoothScrolling": true,
// required to use IntelliSense suggestions
"editor.suggestSelection": "first",
// enable tab completion (complete code by pressing tab)
"editor.tabCompletion": "on",
// if the line is longer than your window, display it on several lines
"editor.wordWrap": "on",
// don't automatically select files in explorer when you open them
"explorer.autoReveal": false,
// don't ask for confirmation when you delete a file
"explorer.confirmDelete": false,
// don't ask for confirmation when you drag and drop a file
"explorer.confirmDragAndDrop": false,
// save your file before switching to another one
"files.autoSave": "onFocusChange",
// set Python as the default language for new files
"files.defaultLanguage": "python",
// always have an empty line at the end of the file
"files.insertFinalNewline": true,
// use VS Code file explorer instead of the operating system
"files.simpleDialog.enable": true,
// remove whitespaces at the end of each line
"files.trimTrailingWhitespace": true,
// automatically fetch repository changes from GitHub
"git.autofetch": true,
// don't ask for confirmation before synchronizing git repositories
"git.confirmSync": false,
// commit all unstaged files using VS Code Source Control Tab
"git.enableSmartCommit": true,
// disable GitLens code lens (distracting)
"gitlens.codeLens.enabled": false,
// disable GitLens annotations on current line (distracting)
"gitlens.currentLine.enabled": false,
// trigger hover for the current line
"gitlens.hovers.currentLine.over": "line",
// create a vertical colored line for indentation
"indentRainbow.indicatorStyle": "light",
// don't ask when restarting Jupyter kernels
"jupyter.askForKernelRestart": false,
// allow to step out of user written code
"jupyter.debugJustMyCode": false,
// create an interactive window per file (see tips and tricks)
"jupyter.interactiveWindow.creationMode": "perFile",
// send the selected code to the interactive window instead of terminal
"jupyter.interactiveWindow.textEditor.executeSelection": true,
// enable the auto-reload extension by default for Jupyter notebooks
"jupyter.runStartupCommands": [
"%load_ext autoreload",
"%autoreload 2"
],
// disable smart scrolling (lock scrolling when output view is selected)
"output.smartScroll.enabled": false,
// automatically format Python imports and code on save
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
"editor.defaultFormatter": "charliermarsh.ruff",
},
// disable redhat telemetry (avoid a popup on first use)
"redhat.telemetry.enabled": false,
// allow untrusted files in the workspace when opened
"security.workspace.trust.untrustedFiles": "open",
// don't synchronize the following settings
"settingsSync.ignoredSettings": [
"projectManager.git.baseFolders"
],
// use the same keybindings on Linux, Mac, and Windows
// note: you might want to drop this setting depending on your keybindings
"settingsSync.keybindingsPerPlatform": false,
// don't ask which problem matcher to use for executing VS Code tasks
"task.problemMatchers.neverPrompt": true,
// disable multiline paste warning by default
"terminal.integrated.enableMultiLinePasteWarning": false,
// enabled stronger integration between VS Code and the terminal
"terminal.integrated.shellIntegration.enabled": true,
// don't automatically open the peek view after running unit tests
"testing.automaticallyOpenPeekView": "never",
// don't follow the test currently running in the Test Explorer View
"testing.followRunningTest": false,
// open the Text Explorer View on failure
"testing.openTesting": "openOnTestFailure",
// ask VS Code to change settings required for running IntelliCode
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
// replace VS Code title bar by the command certer (menu, selections, widgets, ...)
"window.commandCenter": true,
// don't enable mnemonics shortcuts (e.g., ALT + ...)
// this is related to my Alt-key trick, more on that later
"window.enableMenuBarMnemonics": false,
// authorize the title bar to be changed for enabling the command center
"window.titleBarStyle": "custom",
// don't preview file (pending opening state), open them directly instead
"workbench.editor.enablePreview": false,
// focus on the tab on the left instead of the most recent one
"workbench.editor.focusRecentEditorAfterClose": false,
// all open tab will be opened in multiple line (instead of scroll bar)
"workbench.editor.wrapTabs": true,
}
How do you create project-specific settings?
While user settings apply globally, you can define settings specific to a project to ensure consistency across a team. This is a core MLOps practice, as it standardizes the development environment for anyone who clones the repository.
- Create a folder named
.vscode
at the root of your project. - Inside this folder, create a file named
settings.json
. - Add any project-specific configurations to this file.
VS Code will automatically apply these settings when you open the project folder.
Example .vscode/settings.json
:
This configuration automatically enables the Ruff formatter and turns on Pytest for any team member opening the project.
{
// Define Python-specific settings for this project
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
// Enable the project's chosen testing framework
"python.testing.pytestEnabled": true
}
How do you connect the Jupyter extension to your uv
environment?
To ensure VS Code's Jupyter extension uses the correct packages from your uv
-managed environment, you must point it to the right Python interpreter. This enables features like IntelliSense and debugging to work seamlessly within your notebooks.
- Open Your Project: Launch VS Code from the root of your project directory (the one containing
pyproject.toml
and.venv
). - Select the Interpreter:
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
). - Type and select Python: Select Interpreter.
- Choose the interpreter associated with your project. VS Code usually recommends the correct one, often labeled with
.venv
and identified as a virtual environment.
- Open the Command Palette (
- Verify the Connection:
- Create or open a Jupyter Notebook (
.ipynb
file). - Click the kernel selector in the top-right corner.
- Confirm that the selected kernel points to the same
.venv
Python interpreter you chose in the previous step.
- Create or open a Jupyter Notebook (
Now, any packages you add to your project with uv add <package-name>
will be immediately available in your Jupyter notebooks.