Minimum path to a Jupyter Notebook in VSCode

Today I need to do some calculations for an article, so I want to persist them. The best way to do this is in a notebook, in Python. This Jupyter notebook thing that is exactly what I need. And VSCode recently added support for it!

Some numbers. I added and divided some numbers.

The installation instructions for Jupyter are all like “anaconda” and “pip” and other Pythony concepts. And then if you get all that set up, it runs a web server that you have to log in to. Can I just start up a Docker container please?

I tried my favorite VSCode command “Add development container configuration files…” but it doesn’t yet have a Jupyter base image (September 2021). So I had to discover a satisfactory base image and put it in a Dockerfile first.

Here’s a fast path to a Jupyter notebook in VSCode:

0. Have Docker, VSCode, and VSCode’s Remote Containers extension.

1. Create a new directory. Open VSCode there: code .

2. Create Dockerfile with the following thrilling contents:

FROM jupyter/minimal-notebook:notebook-6.4.3

3. Run my favorite VSCode command (Ctrl-shift-P for the prompt): Add development container configuration files...
When it asks what container to use, choose “existing Dockerfile.”

4. It should pop up a window offering to “Reopen in container.” If it doesn’t, enter that at the command prompt (ctrl-shift-P).
It’ll take a while to download that Docker image the first time. Let it start up.

5. Get the Jupyter notebook extension. Choose Extensions (Ctrl-shift-X), search for Jupyter, and find Microsoft’s extension.
Click “Install in Dev Container.”

5a. Optional: to remember this extension installation in future container builds, add it to your .devcontainer/devcontainer.json container definition:

	"extensions": [

6. Create a notebook! At the command prompt (ctrl-shift-P): New Blank Notebook

7. Type some python! Like 1+2 or something easy. Then click Run All in the notebook. It should show you the results.
Use Alt-Enter to “run this cell and make a new one.”

The first time I did this it bugged me to choose a kernel? One of the options was recommended so I clicked it. Whatever VSCode, you know more about this than I do.

There’s a bunch of features to explore. Personally, all I wanted was for these sample averages to come out easy-to-type. So I tweaked my made-up request durations until I got whole numbers for all the answers.

It’s better than a calculator, and also it’s persistent.

Happy calculating!