My Minimal VS Code Setup for Python - 5 Visual Studio Code Extensions
I show you my minimal Visual Studio Code Setup for Python Programming. I use only 5 Extensions. It's simple but allows me to be really productive.
#more
Visual Studio Code (VS Code) is a free source-code editor made by Microsoft and is available for Windows, Linux and macOS. You can download it here: https://code.visualstudio.com/
The editor can be extended via Extensions, available through a central repository. This includes additions to the editor and language support A notable feature is the ability to create extensions that add support for new languages, themes, and debuggers, perform static code analysis, and add code linters. In this tutorial I show you my minimal Visual setup for Python Programming. I use only 5 Extensions. It's simple but allows me to be really productive.
1. Official Python Extension by Microsoft¶
Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python.
A Visual Studio Code extension with rich support for the Python language (for all actively supported versions of the language: 2.7, >=3.5), including features such as IntelliSense, linting, debugging, code navigation, code formatting, Jupyter notebook support, refactoring, variable explorer, test explorer, snippets, and more!
2. Python Docstring Generator¶
Link: https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring.
Visual Studio Code extension to quickly generate docstrings for python functions.
Features:
- Quickly generate a docstring snippet that can be tabbed through.
- Choose between several different types of docstring formats.
- Infers parameter types through pep484 type hints, default values, and var names.
- Support for args, kwargs, decorators, errors, and parameter types
Usage: Write a function first, then go to the beginning of the function and type three double quotation marks ("""
). Then hit enter, and you get a docstring that already contains the input and return variables. You just have to fill out the missing parts. You can easily step to the next missing part by pressing Tab
.
def function(a, b=5):
"""[summary]
Args:
a ([type]): [description]
b (int, optional): [description]. Defaults to 5.
Returns:
[type]: [description]
"""
if a == -1:
print('negative')
result = a * b
return result
3. Python Indent¶
Link: https://marketplace.visualstudio.com/items?itemName=KevinRose.vsc-python-indent.
Get correct indentation when you hit Enter
. Nothing more, nothing less. But it can actually save you a lot of time when writing code.
data = {'a': 0,
'b': 1,
'c': 2}
def function(first,
second)
4. Code Runner¶
Link: https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner.
Run your code file or only code snippets with a short cut. Supports not only Python but multiple languages.
Features:
Usages
-
To run code:
- use shortcut Ctrl+Alt+N
- or press F1 and then select/type Run Code,
- or right click the Text Editor and then click Run Code in editor context menu
- or click Run Code button in editor title menu
- or click Run Code button in context menu of file explorer
-
To stop the running code:
- use shortcut Ctrl+Alt+M
- or press F1 and then select/type Stop Code Run
- or right click the Output Channel and then click Stop Code Run in context menu
5. Linting¶
Lint, or a linter, is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs. It helps you to reduce errors while still writing code, and makes sure you conform to the Style Guide
A linter is not installed via the Extension library, but has to be installed to your site-packages using a package installer like pip
. You can search in the Command Pallete for Select Linter, and then select the one you prefer. I recommend using either pylint or flake8, which are the most popular ones. Select the entry, and you might get a message popup that linting is not yet installed. Go ahead and click on Install, which will install the chosen linter with pip
.
Now when you start writing code and make mistakes or stylistic errors, you see the orange or red hints next to the repsonsible code. You can then hover over these marks and see what exactly is wrong, and can immediately fix it.
Color Theme¶
Currently I'm using the Night Owl Theme. A beautiful dark theme for the night owls out there. Fine-tuned for those of us who like to code late into the night. Color choices have taken into consideration what is accessible to people with colorblindness and in low-light circumstances. Decisions were also based on meaningful contrast for reading comprehension and for optimal razzle dazzle.
I really like this theme, but I also switch from time to time to have some variety.
Conclusion¶
There are many more great Extensions available, like for git support and even special extensions for frameworks like Flask
or Django
. My setup is very minimal, but it works for me. Let me know which Extensions you are using in the comments below the video 😊.
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions: Link*
Python Problem-Solving Bootcamp
🚀 Solve 42 programming puzzles over the course of 21 days: Link*