Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevin-bruton/ba0c439c0958a5e03d25433b849d04cd to your computer and use it in GitHub Desktop.
Save kevin-bruton/ba0c439c0958a5e03d25433b849d04cd to your computer and use it in GitHub Desktop.
Run Jupterlab as an desktop app

How to run Jupyterlab as a desktop app on Mac OSX

Tired of opening terminal to launch Jupyterlab, and having to leave it opened all the time? Try to run Jupyterlab as a desktop app:

nativefier-jupyterlab

One of a benefits is avoiding the annoying accident: "closed Jupyterlab when quitting the browser".

1. Install Anaconda for mac

Run in Terminal

wget https://repo.anaconda.com/archive/Anaconda3-2018.12-MacOSX-x86_64.sh
# get this address from https://www.anaconda.com/products/individual
bash ./Download/Anaconda3-2018.12-MacOSX-x86_64.sh

2. Generate jupter lab configure file

Run in Terminal

jupyter-lab --generate-config

Edit ~/.jupyter/jupyter_notebook_config.py, and add a line, leave token empty to disable authentication; or use a password...

c.NotebookApp.token = ''

3. Build Desktop App with Nativefier

Nativefier github: https://github.com/jiahaog/nativefier

Run in Terminal

# in case you didn't install node: 
# conda install -c conda-forge nodejs

npm install nativefier -g 
cd ~/Applications
nativefier "http://localhost:8888"

This will generate an App in ~/Applications, named Jupyter Notebook, yet, it depends on which command you issue in the terminal:

  • jupyter lab --no-browser --notebook-dir=~/
  • jupyter notebook --no-browser --notebook-dir=~/

The first one recommanded. And if you prefer to use Jupyter Notebook rather than Jupyter Lab, do nativefier "http://localhost:8888/tree".

4. Run Jupyter Lab as a service

4.1

Create a plist file for launchctrl, and save it as ~/Library/LaunchAgents/com.jupyter.lab.plist. Do replace your_username to your username before save the file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>local.job</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/your_username/anaconda3/bin/jupyter</string>
		<string>lab</string>
		<string>--no-browser</string>
		<string>--notebook-dir=/Users/your_username/</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/local.job.err</string>
	<key>StandardOutPath</key>
	<string>/tmp/local.job.out</string>
</dict>
</plist>

4.2

Run in terminal

launchctl load ~/Library/LaunchAgents/com.jupyter.lab.plist

After this, jupyter lab --no-browser --notebook-dir=~/ will run at ever startup.

If you want to restart jupyter lab as service: Run in Terminal

launchctl unload ~/Library/LaunchAgents/com.jupyter.lab.plist
launchctl load ~/Library/LaunchAgents/com.jupyter.lab.plist

4.3

... and here's a handy bash function you can save in .bashrc or .bash_profile, so you can run lctl reload ~/Library/LaunchAgents/com.jupyter.lab.plist in terminal to reload in a single line, or make it an Alfred workflow:

function lctl {
    COMMAND=$1
    PLIST_FILE=$2
    if [ "$COMMAND" = "reload" ] && [ -n "$PLIST_FILE" ]
      then
        echo "reloading ${PLIST_FILE}.."
        launchctl unload ${PLIST_FILE}
        launchctl load ${PLIST_FILE}
      else
        echo "either command not specified or plist file is not defined"
    fi
}

nativefier-jupyterlab-icon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment