Today we're taking a look at the top VS Code Python extensions that every developer should have in their arsenal. Hey guys, welcome back to the channel. If you're new here, my name is Jeremy and this channel is all about helping you to become a better developer with the latest tools and techniques. Alright, let's get started.
Up first on our list is the official Python extension. It's an absolute must-have for any Python developer working in VS Code. So here we are in VS Code and to install this extension, we just come over to the activity bar and click on extensions. and then we search for Python.
We can see that the first result is Python by Microsoft, and it has over 100 million installs. We're just going to go ahead and click on install, and now the extension's installed. After installing the Python extension, you'll see that our installed extensions also includes PyLance and Python Debugger.
These were automatically installed with the Python extension. We can also see that we now have this little beaker icon that's for Python testing. And if we go open up a Python file, We can see in the bottom right corner that we can change the interpreter we're using to run this Python code.
Here I'm using Python 3.9.6. If we type an import statement and then just type a letter R, we see that we get a list of modules that IntelliSense now includes related to Python. So, for example, requests.
We can also set a breakpoint and then come over to debug. Click run and debug. Run the Python debugger. We'll select Python file.
Here it's asking, what's your name? I'm just going to type in Jeremy. and now we can see that we've hit this breakpoint. Our local variables include name, Jeremy, and I can go ahead and click on continue. Again, the Python extension by Microsoft is an absolute must-have if you're developing in Python and VS Code.
Number two on the list is Jupyter. Jupyter notebooks are extremely popular in the Python community. Chances are, if you're writing Python, you've used a Jupyter notebook.
So back in VS Code, we can see that I have the Jupyter extension installed, and now if we open up a Jupyter notebook... And let's just run a simple hello world example. So print hello world. We can see that this is going to be running on Python 3.9.6.
And if I click on run, it prints out hello world. And just like before, if we had a different version of Python installed, we could change that kernel version right there. Number three on the list is auto docstring. It makes it easy to generate docstrings automatically.
So back in VS Code, we can see that I have auto docstring installed. And if I open up this calculator.py file, I can come down. And if we type three double quotes, we see that we get generate doc string.
We'll select that. And now we can fill out the summary. So I'm just going to say add two numbers and then I'll hit tab.
And then I'm just going to say a type of int tab. The description, we're just going to say the first number and then tab again. This is an int as well. And then the second number and it returns a type of int.
And I'm just going to say the sum of X and Y. As you can see. This extension makes it very easy to generate doc strings in Python. Number four on the list is Python Test Explorer.
This extension makes it very easy to run your tests in the sidebar. So back in VS Code, we can see that I have Python Test Explorer installed. And if we take a look at my project, we can see that I have a calculator.py that was used in the previous example, and I have some unit tests for that calculator. Now, if I come down to testing, I can choose configure Python tests.
We're using unit test. We'll select the root directory and we're following the naming convention of test underscore. As you can see, we have two test explorers. The first one is what came by default and the second one is the test explorer extension we just installed. I'm just going to close the first one and now in the second one, we can see both of our tests.
We can run one of the tests and see that it passed or we can run the entire test suite. I can also open the more actions menu and enable auto run. Now, if I come and change one of the tests.
so that it fails and save the file, we can see that it's automatically run in the sidebar. And if I change it back, it automatically passes. This can make testing your Python code a lot faster.
Number five on the list is not exactly Python specific, but it's still a very handy extension to have installed. It's called Code Spellchecker, and it checks your source code for spelling errors. So back in VS Code, we can see that I have Code Spellchecker installed. And now if I open up a random Python file, we could just make some spelling errors.
and we immediately see a blue squiggly line, and here it says it's an unknown word. We can choose Quick Fix, and it's giving suggestions for how to correct this spelling. But this extension doesn't just test strings.
We could also misspell our variable, and it's going to say that's an unknown word, and we can change it to name. I've used this extension for a very long time now, and it saved me from a lot of embarrassing spelling mistakes in my code. I highly recommend you check it out. Number six on the list is CodeRunner.
This extension makes it very easy to run Python code, or really any other code, directly in VS Code. Let's see how it works. So here we are back in VS Code, and we can see that I have CodeRunner installed. Now if you're running on a Mac, CodeRunner doesn't work with Python directly out of the box. We've got to change it so that it runs with Python 3. So to do that, we're just going to open up the settings with Command-Comma, and I'm just going to search for CodeRunner.
And then I'm just going to scroll down and find Executor Map. We're going to choose Edit in Settings.JSON. and then we're going to scroll down and find Python and then I'm going to change this run command to Python 3 and save the file.
And now if I open up a Python file we can type some random code. So I'm just going to do hello world hello world and now I can select this code. and hit control alt N and it runs that code. We can also not select anything and hit control alt N and it runs the entire file.
Here we can see, hello Jeremy and hello world. As you can see, this extension makes it very easy to run Python code. This can be very helpful if you're just testing out some code real quick.
Number seven on the list is Python Environment Manager. Python Environment Manager makes it super easy to view and manage your Python environments. So back in VS Code. we can see that I have Python Environment Manager installed. And now once it's installed, we see an additional icon in the activity bar.
If I click on it, we can see that here's my workspace environment and here's my global environments. We can open up the info dropdown and see that I'm running version 3.9.6 on a 64-bit environment. We can also take a look at the packages that I have installed in this environment and what version the packages are.
We have options to install packages, refresh, and update all packages. We can also create new environments. Let's create a new virtual environment. So I'm just going to come down to VM and click on the plus sign.
And then in this environment, I'm just going to run 3.9.6. And now we have a new virtual environment that we can install packages in. If we want, we can set it as our active workspace interpreter. And then when we're done with it, we can delete the environment.
I consider this plugin to be another absolute must-have in VS Code if you're writing Python. Number eight on the list is Areple for Python. It automatically evaluates and shows the result.
of your Python code directly in VS Code in real time. So let's check that out. So here we are in VS Code, and we can see that I have arepal for Python installed.
So now if I open up a Python file, we see that we get a new icon in the top right corner. If I click on it, it says start typing or make a change, and your code will be evaluated. So we'll just come back to the code and add a new line. And now we can see the output of our code.
This output is from line 14, where we print the result. We can also see the value of all of our variables in the code. Let's say, for example, we don't want the value of variable 0.1. We can filter those out.
So to do that, we're just going to say a REPL underscore filter equals an array of strings, and the string is the name of the variable, so 0.1. And now we can see that 0.1 is no longer showing in the variables list. We can also just disable this functionality altogether.
So to do that, we'll just open up settings with command comma, and then search for a REPL space. VARS and we can come down where it says show global VARS and turn it off. Now if we come back to the code and make a change we can see that areple is configured to not show global VARS.
While we're in the settings we can also change the delay before it executes the code. Here we can see it's set to 300 milliseconds. This plugin is great for quickly executing Python code and seeing the result in real time.
Number nine on the list is Python Snippets. This extension adds a vast collection of Python snippets directly into VS Code. So here we are in VS Code, and we can see that I have Python snippets installed.
So now if I come over and open up a Python file, I can open the command prompt with command shift p and search for insert snippet. And here we can see a list of all of the snippets that Python snippets adds. So for example, defining a function. If I select that, it adds a function definition to the editor. If you want to learn more about snippets in VS Code, I have an entire video covering this.
you can check it out right here. And last on the list at number 10 is Error Lens. Error Lens highlights your errors and warnings directly in the editor beside your code. Let's see how that works. So back in VS Code, we can see that I have Error Lens installed.
And now if I open up some code, let's open this messy code.py, we can see all of our errors are highlighted in red directly inside our code. So for example, unexpected indentation. And if I remove this indentation, we see that the error immediately goes away.
And that wraps up our rundown of the top VS Code extensions for Python developers. If you're looking to level up your VS Code game even further, check out this other video where I go over the best VS Code feature, the command palette. Also, I've just launched a weekly newsletter that covers the same content you'll find on this channel, except in bite-sized, easy to digest pieces.
It's perfect for your busy schedule. You can sign up on my website and I'll leave a link in the description below. Thanks for watching, and I'll see you in the next one.