How to Configure Visual Studio Code for Python Development (2024)

Visual Studio Code is one of the most versatile code editors out there. Even though it's a code editor, the sheer extensibility of the program makes it almost as capable as some of the JetBrains products out there.

In this article, I'll walk you through the entire process of configuring Visual Studio Code for Python development. It's not a universal setup, but this is something that I use personally and have found it to be really comfortable.

The first step is to install Visual Studio Code on your computer. I'm on Debian 12 at the moment and I have the editor ready to go. Platform specific installation instructions are available in the documentation.

Assuming you are past the installation step, now I'll introduce you to a set of essential extensions that will elevate your Python development experience to the next level.

Python Extension

The first extension that you need to install is the Python Extension from Microsoft.

How to Configure Visual Studio Code for Python Development (1)https://marketplace.visualstudio.com/items?itemName=ms-python.python

This is actually an extension pack that contains two extensions. The first extension is the Python extension. It lays the foundation for Python development in Visual Studio Code.

The other one is Pylance, which is a very performant language server for Python.

How to Configure Visual Studio Code for Python Development (2)https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance

This extension provides rich intellisense support and is powered by Pyright, the static type checker from Microsoft. The next thing you need to think about is linting.

Ruff Linter

A linter is a program that analyses your code statically and provides valuable insights on possible errors.

The Pylance extension does an excellent job of finding out fatal errors within your code, but there is more to code than just that.

When working on a big project, it's pretty common to leave unwanted mess within your codebase. Things like unused imports and variables, bad code practices, and so on.

A good linter can point out code smells like this and make your code cleaner. Now, the go-to choice when it comes to Python linters is Pylint.

Pylint has been around for ages and works quite well, but I think there is a better alternative.

Ruff is an extremely fast Python linter written in Rust that imposes stricter linting rules than Pylint. The tool also has an official extension.

How to Configure Visual Studio Code for Python Development (3)https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff

It's a plug n' play extension and doesn't require any additional configuration whatsoever. So once you have it installed, you're good to go.

Isort

Like a linter, isort is another utility that's sole purpose is sorting import statements.

How to Configure Visual Studio Code for Python Development (4)https://marketplace.visualstudio.com/items?itemName=ms-python.isort

The utility sorts all the imports alphabetically, while also dividing them into sections.

The extension is very straightforward. Once you have the extension, it'll render squiggly lines under any import statement that seems out of place.

You can then use the quick action menu to sort them. Or, you can also use the command palette to quickly access the isort command.

Mypy Type Checker

Before I start talking about this extension, let me explain what mypy actually is.

According to the info on their homepage:

Mypy is an optional static type checker for Python that aims to combine the benefits of dynamic (or "duck") typing and static typing. Mypy combines the expressive power and convenience of Python with a powerful type system and compile-time type checking.

In simpler words, mypy forces you to add essential type annotations to your Python programs, making them easier to comprehend.

How to Configure Visual Studio Code for Python Development (5)https://mypy-lang.org/

Recently, Microsoft has published an extension that adds type checking functionality using mypy to their beloved editor.

How to Configure Visual Studio Code for Python Development (6)https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker

Once you have installed the extension, it'll perform necessary checks on your code and report any missing type annotations as compile-time errors.

While having type annotations is not mandatory, it's highly recommended.

IntelliCode

IntelliCode provides AI assisted code completion in Visual Studio Code. It may sound similar to GitHub Copilot, but in reality it's a lot smaller than that.

How to Configure Visual Studio Code for Python Development (7)https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode

Where GitHub Copilot or Tabnine provides full-blown code blocks, IntelliCode autocompletes lines of code pretty flawlessly.

In most cases, this extension can help you type less of the same code by suggesting the right thing while also keeping out of your way.

Error Lens

While not related to Python specifically, Error Lens is a great extension that embeds errors right by the side of the line of code.

How to Configure Visual Studio Code for Python Development (8)

I often work on my 14 inch Thinkpad and like to turn off the terminal pane. Error Lens eradicates the need to look at the terminal now and then to see my errors and warnings.

As useful as it may be, sometimes your editor can look cluttered due to all the warning and error outputs, so decide accordingly.

Indent Rainbow

Unlike other programming languages, an incorrect level of indentation can literally break your program in Python.

Visual Studio Code already does a good job of visualizing indentation levels within your code, but if you want to add some color to it, the indent-rainbow package is what you need.

How to Configure Visual Studio Code for Python Development (9)https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow

It adds different colors to the different levels of indentation. Personally, I don't use this one on a regular basis, but you may find it useful.

Conclusion

Like I said, these extensions and my personal configuration are not a silver bullet. But this setup is something that I've been using for quite a while and I hope it's useful to you as well.

I often install specialized extensions depending on the projects I work on. For example, I use the Django or Jinja project when I work on a Django or Flask project.

Or I install the Jupyter extension while working on a Jupyter Notebook. So feel free to install whatever you need, just don't overdo it.

How to Configure Visual Studio Code for Python Development (2024)
Top Articles
Equities: What happens after the first rate cut?
NodeJS for Data-Intensive Application: Cases & Best Practices
Dunhams Treestands
Diario Las Americas Rentas Hialeah
Edina Omni Portal
Rubratings Tampa
Walgreens Pharmqcy
Noaa Swell Forecast
Puretalkusa.com/Amac
Nikki Catsouras Head Cut In Half
Music Archives | Hotel Grand Bach - Hotel GrandBach
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Helloid Worthington Login
Ukraine-Russia war: Latest updates
Cnnfn.com Markets
Rainfall Map Oklahoma
Craigslist Malone New York
Bcbs Prefix List Phone Numbers
Procore Championship 2024 - PGA TOUR Golf Leaderboard | ESPN
111 Cubic Inch To Cc
24 Hour Drive Thru Car Wash Near Me
Walmart Car Department Phone Number
*Price Lowered! This weekend ONLY* 2006 VTX1300R, windshield & hard bags, low mi - motorcycles/scooters - by owner -...
Scream Queens Parents Guide
Employee Health Upmc
Mybiglots Net Associates
Slim Thug’s Wealth and Wellness: A Journey Beyond Music
Hdmovie2 Sbs
Cpt 90677 Reimbursem*nt 2023
Craig Woolard Net Worth
Ltg Speech Copy Paste
Water Temperature Robert Moses
Dal Tadka Recipe - Punjabi Dhaba Style
Jesus Calling Feb 13
R3Vlimited Forum
CARLY Thank You Notes
Flashscore.com Live Football Scores Livescore
Afspraak inzien
Page 5662 – Christianity Today
Legit Ticket Sites - Seatgeek vs Stubhub [Fees, Customer Service, Security]
2700 Yen To Usd
2007 Jaguar XK Low Miles for sale - Palm Desert, CA - craigslist
Amc.santa Anita
Tricare Dermatologists Near Me
Bmp 202 Blue Round Pill
Crystal Glassware Ebay
What Does the Death Card Mean in Tarot?
Mawal Gameroom Download
Grandma's Portuguese Sweet Bread Recipe Made from Scratch
Www Extramovies Com
Www.card-Data.com/Comerica Prepaid Balance
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5775

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.