Setting up python Black on Visual Studio Code

2 min readOct 1, 2019

--

To setup python black as a formatter for VS-Code workspace you need to install it on your virtual env or in your local python with the command:

$ pip install black

Now install the python extension for VS-Code, open your VS-Code and type “Ctrl + p”, paste the line below and hit enter:

ext install ms-python.python

We are almost there. Go to settings in your VS-Code typing “Ctrl + ,” or clicking at the gear on the bottom left and selecting “Settings [Ctrl+,]” option.

Type “format on save” at the search bar on top of the Settings tab and check the box.

Search for “python formatting provider” and select “black”.

Now open/create a python file, write some code and save(Ctrl+s) it to see the magic happen!

Example

Before saving the file.
After saving the code automatically get formatted

Good to know: if Black is not working maybe your python code has some syntax error, recheck the code and test again.

Contact me: linkedin.com/in/marco-belo/

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (4)

Write a response