How to Lint Your Jupyter Notebook With Python Black

Emily Ekdahl
Jan 29, 2022

First, be sure that you are working in a virtual environment so that you’re managing packages and dependencies safely! If you’re not, check out my article on how to set up virtual environments for your Jupyter Notebook.

Next, install Python Black for Jupyter Notebooks.

pip3 install black[jupyter]

Note that if you’re using zsh you may need to escape the brackets with a backslash!

pip3 install black\[jupyter\]

Once you’ve installed it, remember you might need to source your zsh profile again or open a new terminal window.

source <your_virtual_environment_name>/bin/activate

Then, run this command to lint your notebook:

black path/to/your/file.ipynb

When linting is complete, you should see this message:

I just love seeing the sparkle cake emoji! Don’t you?

--

--