4/15/2019

Set up Visual Studio Code for python in few minutes

A few days ago, I began working on a python project again. It has been over a year since I wrote python. Back in the days, I chose VIM and Pycharm for python when it comes to IDE. However, I started shifting some jobs or projects to visual code recently. Also, I got used to Visual Studio Code a little bit. Therefore, I spent a day to search and understand how many extensions are required to make Python development in Visual Studio Code a better experience. Here, I will list useful extensions and python packages I installed.

Python packages


autopep8 automatically formats Python code to conform to the PEP 8 style guide:

pylint is a static code analysis tool which looks for programming errors:

If you choose pytest for your unit test, you have to install those:

Visual Code Extensions


1. Python Microsoft

Download: https://marketplace.visualstudio.com/items?itemName=ms-python.python
An extension with rich support for the Python and it contains linting, debugging, code navigation, code formatting, refactoring, unit tests, snippets, and so and so. This is a basic and necessary extension!

2. Python autopep8

With this, it can allow you to do auto-formatting in your Visual Studio Code.

3. py-coverage-view

The extension highlights test coverage in Visual Studio Code. It helps me to understand which line is not tested without looking at the console output.

4. Python Indent

I just installed because it looked neat.

5. GitLens — Git supercharged

GitLens helps you quickly find out whom, why, and when a line or code block was changed.

6. Trailing Spaces

It helps you remove annoying trailing spaces..

7. autoDocstring

This one makes you write python document easier.

8. Importmagic

Download: https://marketplace.visualstudio.com/items?itemName=brainfit.vscode-importmagic
It claims it can help me to import module automatically, but it seems it cannot work on my VSCode for unknown reasons.

9. Spell check

Download: https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker
Needless to say, this extension is to check your spelling in your code or README.

10 Material-icon-them

Download: https://marketplace.visualstudio.com/items?itemName=PKief.material-icon-theme
This is an extension to beautify your folder and file with icon-based Material design.

11 Bracket Pair Colorizer

Download: https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer
It makes the code easier to identify matching brackets like ( [ { } ] ).

12 Python Test Explorer

Download: https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
This extension allows you to run your Python Unittest or Pytest tests with the Test Explorer UI.

13. VIM

Download: https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
For Vim users, it is a Vim emulation for Visual Studio Code
As a side note, if you are a mac user and you want to press vim navigation key in mac to move the cursor, you have to type this in your terminal 
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

14. GlobalConfig

After installing certain extensions, you might need to configure the settings for each project. GlobalConfig offers a solution to this. Therefore, you can create a global setting under ~/.vscode/settings.json which has the default settings. Here is an example

15. Sync your VSCode settings

Once you installed so many extensions in your VSCode, there is another extension to sync your settings across machines. For more information, you can follow this page: https://itnext.io/settings-sync-with-vs-code-c3d4f126989

Note

As a side note, VSCode keeps track of each folder if they were changed. As a result, it takes up lot of memroy and opens lots of file descriptors leading to horrible perfromance on your computer. If you want to exclude certain folders or files, you can reference this post.
https://stackoverflow.com/questions/33258543/how-can-i-exclude-a-directory-from-visual-studio-code-explore-tab



3 comments: