Run Jupyter Notebooks as a Service on macOS

Posted on Aug 31, 2017

I was looking for a way to run jupyer notebook without using a constantly open terminal or a screen session. On macOS there is a way to create services using a .plist file and the launchctl command.

Because I use different environments for all Python related stuff, it wasn’t immediately clear to me how to do this when I’ve installed Jupyter only in a pyenv. After some fiddling around, I finally solved it. The key was to set the working directory parameter to the directory in which the environment is loaded. In my case this is ~/notebooks where I automatically load the env by using a .python-version file.

Below you find the .plist file, that enables you to start/stop the notebook server using launchctl <start|stop> local.jupyter.notebook.

It assumes that you have a Python environenment in /Users/USERNAME/notebooks. So simply change it to your needs. Put the file into /Users/USERNAME/Library/LaunchAgents and call launchctl load PATH_TO_FILE once to load it. After this you can start/stop the service as described above.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">