Why I’m Using VSCode for Jupyter Notebooks
By: Alan Jones
Tags: Data Science, Vscode, Programming, Jupyter Notebook, Python

Why I’m Using VSCode for Jupyter Notebooks

The first time that I used VSCode to open a Jupyter notebook was a complete accident.

I use VSCode for writing standalone Python scripts and Flask apps but I’ve always used the standard browser interface for running Jupyter notebooks. Frankly, it never occurred to me to do anything else.

But one day I was browsing through my file manager, looking for a particular notebook that I’d somehow managed to lose in the maze of project folders that comprises my D: drive. I eventually found it and for some reason — default behaviour, I suppose — I double clicked on it. Now, as I said, VSCode is my default Python editor so double clicking on a Python file will bring that file up in the editor. Did I also make it the default for ipynb files, too? I don’t remember but I suppose I must have because VSCode leapt into action and opened the notebook.

Oh no! That’s not what I meant to do.

What I intended was to open a command line window, navigate to my notebooks folder, type jupyter notebook , wait for the Jupyter server to fire up and the browser to get going, open the notebook that I wanted and, finally, start editing it.

And I’d basically done precisely the same thing by simply double clicking. Perhaps I was on to something. If nothing else, the simplicity of opening a notebook using VSCode suggested to me that it ought to be worth looking at.

And it turns out that it was.

Actually, there is nothing very different between writing and running notebooks in VSCode and doing the same thing in a browser. You still need Python and Jupyter installed and the functions available are pretty much the same. But the familiarity of VSCode, the ease of opening a notebook and the fact that I often have it open anyway means that it has rapidly become my default Jupyter editor.

And then there is IntelliSense and the Variables window — but more on that later.

The VSCode interface

You can see the VSCode window in the main image at the top of the article. It’s the usual VSCode interface but above the editor window is a menu bar for Jupyter Notebook functions and, apart from file functions like opening a new file, or saving the current one, you won’t need much else.

Here is a close-up of a typical code cell and the main Jupyter menu options.

You run a cell by selecting it and typing ctrl-Enter, as usual (there should also be a run symbol on the left of the cell that you can click on).

Markdown cells are similarly familiar.

Hit ctrl-Enter and you will get this:

Notice that the toolbar has moved to the right in the last image. There is nothing magic about that; I changed it by toggling its position by selecting the … option and choosing one of the options from the dropdown menu as you can see below.

Cell toolbar options — image by author

This also allows you to insert new cells, merge them, split them… well you can see the options in the screenshot.

IntelliSense

I like this a lot. Sometimes I forget how to use some of the functions that I don’t use that often: what was that name again, what parameters do I use? Intellisense comes to the rescue.

As you can see below, if you start typing the name of an object (here it is a Pandas DataFrame) — when you hit the . Intellisense will prompt you with what options are available and how to use them.

Variables

The variables window is another bonus. Variables is an option in the main Jupyter toolbar which opens a window like this:

We can see that it gives you the name, type, size and value of each of the variables that have so far been defined.

Export

The export functions are the same as you will find in the standard Jupyter interface (export to Python, HTML or PDF) but you can also save images directly from the icon that appears to the right of them which can be useful if you are creating a document.

Conclusion

To be perfectly honest, I don’t use VSCode all the time, I like the browser-based Jupyter editor, too, (and it seems to work a little better with the touchscreen on my little tablet PC — but that might just be a foible of this particular piece of hardware).

But my takeaway from this is that VSCode is convenient and does everything that you might want to do with a Jupyter notebook. Why not give it a try!