Jupyter, or officially Project Jupyter, is an open-source project aimed to support interactive data science and scientific computing across all programming languages.

In this post I’ll go through my favorite setup for JupyterLab, a browser based interactive IDE born out of the Jupyter Project.

Dependencies

Make sure the following are installed:

Setup

This next section will go through my opinionated setup for JupyterLab. It covers some of the features of JupyterLab that I have found to make it easier to launch the application, develop notebooks, and collaborate.

Repository

Storing notebooks in GitHub is a great way to keep track of your work and share your work with others. GitHub can render the notebooks and markdown which makes it easy to browse and view notebooks from anywhere. A great example repository can be found at https://github.com/sinclam2.

First, create a new repository. If you are using GitHub, click the ‘New’ button on the ‘Repositories’ tab. new-repository

Next, copy the repository URL. clone-repository

Then clone the repository.

git clone https://github.com/<username>/notebooks.git

Create a file called .gitignore in the cloned repo with the following content:

# Vim
*~

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Jupyter Notebook
.ipynb_checkpoints

# Pipenv
Pipfile.lock

# Environment
.env

# Node
node_modules

Pipenv

Pipenv is a great package manager for Python which makes it easy to set up projects and manage virtual environments.

Create a new virtual environment in your repository directory created above.

pipenv --python 3.7

This will create a new Python virtual environment located in ~/.venvs/. It will also create a new file named `Pipfile` which will track the Python dependencies.

Jupyter

Install JupyterLab.

pipenv install jupyterlab

Start JupyterLab.

pipenv run jupyter lab

Your default browser should open the jupyter lab URL.

You should now see the JupyterLab IDE in your browser window! :tada: jupyterlab-start

Jupyter Config

Generate the Jupyter config which we will use to customize Jupyter.

pipenv run jupyter lab --generate-config
Writing default config to: C:\Users\andy\.jupyter\jupyter_notebook_config.py

Find the c.NotebookApp.browser setting and add the following:

## Specify what command to use to invoke a web browser when opening the notebook.
#  If not specified, the default browser will be determined by the `webbrowser`
#  standard library module, which allows setting of the BROWSER environment
#  variable to override it.
c.NotebookApp.browser = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe --app=%s'

This tells Jupyter to open Chrome in app mode which makes for a better experience when using JupyterLab. If you’re not using Chrome, :confused:.

You can always run with your default browser by start the application with:

pipenv run jupyter lab --browser=''

GitHub Extension

The JupyterLab GitHub extension provides a clean way to browse and use notebooks stored in other repositories. If you work with a team that uses Jupyter extensively, this is a great way to collaborate.

Install the extension.

pipenv run jupyter labextension install @jupyterlab/github

Make sure you have the latest Node LTS version installed. Instructions for Windows.

Install the server extension:

pipenv install jupyterlab_github

Next we need to generate a GitHub Personal Access Token so that calls to the GitHub API are not rate limited. Navigate to your GitHub dashboard and then select ‘Settings’ under your user dropdown. github-settings

Then in the left column select ‘Developer Settings’ and then ‘Personal access tokens`. Click the ‘Generate new token’ and store the token in a safe place (I recommend 1Password). personal-access-token

Open the generated config file from above and add the GitHub access token:

# Configuration file for jupyter-notebook.

c.GitHubConfig.access_token = '< YOUR_ACCESS_TOKEN >'

There is not a section for GitHub so just add it at the top somewhere.

If you restart JupyterLab you should now see a GitHub tab which you can use to browse repositories. jupyter-github-extension

Git Extension

The JupyterLab Git extension allows you to commit and push changes to your repository without having to leave the application.

Install the extension.

pipenv run jupyter labextension install @jupyterlab/git

Install and enable the server extension.

pipenv install jupyterlab-git
pipenv run jupyter serverextension enable --py jupyterlab_git

Restart JupyterLab and you should see a new Git tab. jupyter-git-extension

Vim Extension

Optionally install the VIM extension. This makes it much faster to navigate the notebook cells if you are familiar with VIM :zap:.

pipenv run jupyter labextension install jupyterlab_vim

Restart JupyterLab and you can now use VIM key bindings to navigate the cells and edit code.

Summary

In this post we covered installing JupyterLab and the GitHub, Git, and VIM extensions. I hope you found the instructions helpful. If you have any questions or if you run into any issues let me know in the comments below :point_down:.

Resources