Jupyter Notebooks boost

Khalimbetov Ulgubek
5 min readSep 2, 2021

discovered Jupyter Notebooks a few months ago when I got serious about machine learning. The way everything works in the browser, at first frankly amazed, but rose-colored glasses quickly fell asleep: it became clear that the interface lacked basic useful functions. Then I decided to master the tricks of working with Jupyter Notebooks.

If you follow the instructions below, the following functions will appear in your Jupyter Notebook (by the way, this is not the limit):

  1. Ability to switch between multiple Conda environments on the fly without restarting Jupyter Notebook.
  2. Create Table of Contents in one click (you will appreciate it!).
  3. An incredibly useful pop-up Scratch Pad (notepad, my favorite!) Where you can test the code and experiment without changing anything in the main body of the code.
  4. 4. Code Folding I don’t understand why this feature was not introduced earlier.
  5. 5. Code Cell hiding is an important feature if you are presenting data history through visualization .. people are more interested in graphs and charts than in the code itself!
  6. Very cool Variable Inspector.
  7. Spellchecker for markdown cells.
  8. Zen Mode that hides all unnecessary distractions.
  9. The Code Snippets menu allows you to add Python constructs on the fly, such as List comprehensions.
  10. And finally, the best of the features is a calm, beautiful midnight theme for your eyes!

Time to Start!!

Let’s start by setting up a relaxing dark theme. Long work in a program with a light background makes your eyes very tired. Be that as it may, once you have crossed to the dark side, you will not be able to return.

To install the dark theme, follow the instructions below:

# Shut down the Jupyter Notebooks server and exit
# Make sure you are in the base conda environment
conda activate base
# install jupyterthemes
pip install jupyterthemes
# update to the latest version
pip install — upgrade jupyterthemes

When the package is installed and updated, write the following command and feel free to switch from the light theme to the dark blue midnight. Your eyes will appreciate it.

# Turn on Dark Mode
jt -t onedork -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T

Now let’s see if we can add the custom environments created in Anaconda as kernels in Jupyter Notebooks. This will allow fast switching through the Kernel menu without restarting the environment.

Let’s say you’ve created two custom environments in Anaconda: my_NLP and gym. To add them to Jupyter Notebooks, you need to:

# Stop the Jupyter Notebooks server and exit
# Activate the environment through the terminal
conda activate my_NLP
# Install IPython Kernel
pip install ipykernel
# Bind custom environment to Jupyter
python -m ipykernel install --user --name = my_NLP
# Repeat the steps above for the second environment
conda activate gym
pip install ipykernel
python -m ipykernel install --user --name = gym

Now open Jupyter Notebooks, go to the Change Kernel menu and … Boom! Here is a list of cores that you can switch between in one click.

To configure the rest of the features, you will need to install

Nbextensions for Jupyter Notebooks. To install, follow the instructions:

# Stop the Jupyter Notebooks server and exit
# Make sure you are in the base environment
conda activate base
# Install nbextensions
pip install jupyter_contrib_nbextensions
# Install the required JS and CSS files
jupyter contrib nbextension install — system

As you can see, the list is extensive and not easy to figure out at first glance. Also, not all features are created equal. Here are the ones I use:

Table of Contents — creates content for the entire notebook in one click, immediately with hyperlinks to different sections of the code.
Scratchpad — I think this is the best extension. Allocates space to experiment with some of the code, allowing you to abstract from the rest and leave the code in the main notebook unchanged.
Codefolding — allows you to collapse blocks of code.
Hide Input All — hides the entire array of code, leaving the output and labels visible. Useful if you are trying to explain how a program works to someone who does not understand the technical details.
Variable Inspector — Reduces debugging time, similar to the Variable Inspector in Spyder IDE.
Spellchecker — check spelling in markdown cells.
Zen Mode.
Snippets Menu — Cool collections of commonly used code snippets from list comprehensions to pandas, including everything in between.

Above is a list of the features I use, but feel free to try out the rest. Some of the interesting features I didn’t mention are ScrollDown, table_beautifier, and Hinterland.

NOTES!!

  1. If you don’t have Anaconda installed, simply ignore commands that include “conda”. You can skip the points about adding Anaconda environments to Jupyter Notebooks.

2. You will need administrator rights to install the extensions.
3. If you don’t like working with the dark theme, enter the jt –r command in the terminal to bring back the light theme. If nothing has changed, restart the program and clear the browser cache.

--

--

Khalimbetov Ulgubek
0 Followers

Web Developer, Student at Sejong University