Productivity Tips for Jupyter Notebook
Here are some tips to make you more productive with .ipynb
files (i.e. Jupyter notebooks).
IDE
First, don’t ever directly use Jupyter notebooks!
Instead, you should either use VSCode or Jupyter Lab to work with .ipynb
files.
As you can see below, Jupyter notebooks are extremely sparse and don’t provide any of the benefits of an IDE.
Use VSCode
Your best option is to use VSCode to run and write .ipynb
files.
This allows you to benefit from the full power of VSCode, including keyboard shortcuts, extensions (e.g. Github Copilot), a file browser, an embedded terminal, debugger, etc.
To install:
Open up VSCode and install the following extensions:
- Jupyter
- Jupyter Keymap
- Jupyter Slide Show
- Jupyter Cell Tags
- Jupyter Notebook Renderers
To run:
Simply open up the .ipynb
file in VSCode
Demo:
Here’s what an .ipynb
notebook loaded in VSCode looks like:
Note: You may need to explicitly tell VSCode what Jupyter Kernel to use for running your .ipynb
file. You can do so by clicking the “Select Kernel” button in the top right of the screen. In the image above, I’ve selected base
as my environment.
Use Jupyter Lab
If you can’t use VSCode, the second best option is to use Jupyter Lab, which was developed by the creators of Jupyter.
To install:
pip install jupyterlab
To run:
jupyter lab
Demo:
Here’s what an .ipynb
notebook loaded in Jupyter Lab looks like:
Cells
Add these snippets as cells to the top of your .ipynb
files.
Autoreload Imports
This snippet tells Jupyter to automatically reload imported modules whenever their contents change.
%load_ext autoreload
%autoreload 2
For example, lets say you are actively editing a file called utils.py
that you import into your notebook with import utils
. Whenever you save changes to utils.py
, you’ll have to rerun import utils
, which can be annoying if you’re doing frequent edits. With this snippet, Jupyter will intelligently re-import utils
whenever you edit utils.py
.
Extensions
TBD