Launching Jupyter notebook server on startup
Background
Jupyter notebooks provide a useful interactive environment (think better alternative for console) for scripting languages like Python, Julia, Lua/torch, which has become a favourite tool of many data scientists for handling datasets that fit into the laptop’s memory. If you have not used it, try it next time you do data analysis or prototype an algorithm.The Pain
There is a slight technical difficulty, though. The way Jupyter works is you run a server process on your machine (or somewhere in the network), and then access it through a web client. I have noticed a popular pattern of usage in the local-server case: a user runs the command to start the server process in the terminal then keeps the terminal window open while she is using the notebook. This method has several flaws:- you need to run the process manually each time you need a notebook (after reboot);
- you have to remember the command line arguments;
- the process takes up a terminal window/tab, or, if you run it in the background, you can accidentally close the tab and your RAM state will be lost.
The Solution
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.blippar.jupyter-ipython</string>
<key>ProgramArguments</key>
<array>
<string>zsh</string>
<string>-c</string>
<string>source ~/.zshrc;workon py3;jupyter notebook --notebook-dir /Users/roman/jupyter-nb --no-browser</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/Users/roman/Library/LaunchAgents/jupyter-notebook.stderr</string>
<key>StandardOutPath</key>
<string>/Users/roman/Library/LaunchAgents/jupyter-notebook.stdout</string>
</dict>
</plist>