Tired of opening terminal to launch Jupyterlab, and having to leave it opened all the time? Try to run Jupyterlab as a desktop app:
One of a benefits is avoiding the annoying accident: "closed Jupyterlab when quitting the browser".
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
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 = ''
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"
.
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>
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
... 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
}