Installing Jupyter

Author

Matthew DeHaven

Published

April 6, 2024

This is a guide for installing and setting up Jupyter to use with Visual Studio Code.

If you do not already have VS Code installed, install it here.

You also need to have installed Python.

Installing the Jupyter VS Code Extension

In VS Code, we need to install an extension to support Julia.

This is done most easily from within VS Code, by clicking on the “Extensions” tab and searching for “Jupyter”.

Create an Environment

  • Open a folder in VS Code as a workspace

  • Open the Command Palette (Shift+Cmd+P), and use “Python: Create Environment…”

    • Choose “venv” and the version of Python you want to use

We will install and use jupyter in this local Python environment.

Install Jupyter

  • Launch a terminal in VS Code and run the following:
terminal
pip install jupyter

Jupyter is now installed in your environment!

Edit Jupyter Notebook in VS Code

  • Create an empty file called “example.ipynb”, open it in VS Code

VS Code will recognize it as a Jupyter Notebook and display it as below.

Before we can run any code, we need to select a kernel to use.

  • Click “Select Kernel”, then “Python Environments…”, then “.venv”

The “.venv” environment should be the local environment you created above before installing jupyter.

Now you can add code blocks or markdown blocks, and execute each with either the “play” buttons or the Shift+Enter shortcut.

Edit Jupyter Notebook in Browser

Instead of editing Jupyter Notebooks directly in VS Code, we can use the Jupyter browser-based editor.

  • Run the following in the terminal to launch it:
terminal
jupyter notebook

This should launch a screen like the following in your browser:

This window shows the folder in which we are working. At the moment, there is only one notebook file in the folder, “example.ipynb”.

  • Open “example.ipynb”

You should see the following editor screen (still in your browser):

From here you can also add new markdown and code cells, execute them, and see the results.

You can use this built-in jupyter notebook editor without VS Code as it just requires the jupyter package.

Use a Julia Kernel

In order to use Julia in a Jupyter Notebook you must first have installed Julia.

You should install the following package to the default Julia environment (i.e. system-wide).

  • Install the IJulia package.

  • Create a new Jupyter Notebook file

  • Click “Select Kernel”, then “Julia 1.10.2”

You can now use Julia in your code cells for this document.

Use an R Kernel

In order to use R in a Jupyter Notebook you must first have installed R.

You should install the following package to the default R environment (i.e. system-wide).

  • Install the IRkernel package.

  • Run the following in an R terminal:

IRkernel::installspec()

This command registers R as a kernel to use for Jupyter.

  • Create a new Jupyter Notebook file

  • Click “Select Kernel”, then “Jupyter Kernel…”, then “R”

You can now use R in your code cells for this document.