Nathaniel Brown's

Directions For Running Jupyter In The Background On Windows

Written October 27, 2016

I love the Jupyter Notebook, but I hate starting it and managing my running servers. These directions will leave you with a server that is always running with access to your entire C drive. It should work on Windows 7, 8, and 10. Implementing this saves me whole minutes a day!

Jupyter Primer

To install jupyter: run pip install jupyter at a command prompt. To launch a notebook run jupyter notebook. This should open the jupyter notebook in a browser by default. Now we will make it so you never have to run jupyter notebook again.

Windows Setup

I tried setting up a service using win32service, but this very difficult and I settled on a simple Scheduled Task.

  1. Open Task Scheduler and under "Actions" in the right hand pane, click "Create Task..."

  2. Under the "General" tab:

    1. set a name like "JupyterNotebook"
    2. Make sure the user account is set to the account you want to use
    3. Select "Run only when the user is logged in"
  3. Under the "Triggers" tab:
    1. Create a new trigger (click "New...")
    2. Set "Begin the task:" to "At log on"
    3. Select "Specific user:" and set the user to be the user you selected in step 2.2
    4. Click OK
  4. Under the "Actions" tab:
    1. Create a new action
    2. Set the "Program/script:" to be a path to a pythonw.exe executable in your desired Python installation. I use Anaconda, so my path was C:\Anaconda\pythonw.exe. pythonw.exe is like python.exe, but it is windowless. Type where pythonw at a command prompt to get the path for the version of python you are currently using if you are unsure.
    3. Set "Add arguments:" to C:\Anaconda\Scripts\jupyter-notebook.py --no-browser --ip=127.0.0.1 --port=8001 --notebook-dir=C:\notebooks. Adjust the path to jupyter-notebook-script.py for your installation location, as you did for the previous step (you should be able to run where jupyter-notebook-script.py to get the path). You can adjust the flags passed to the notebook script as you wish, run jupyter notebook --help for available options. The --notebook-dir=C:\notebooks is important though. You cannot mount a notebook on C:\, but you can mount it on a shortcut that points to root. We will create C:\notebooks next.
  5. Click "OK" to complete the task.
  6. Run mklink /D C:\notebooks C:\ at an Amin CMD prompt (search "cmd", right click and "Run as administrator"). This will create a symbolic link at C:\notebooks that will point to C:\. This will bypass jupyter's refusal to mount on C:\.
  7. Start your task by right clicking your new task in the list of tasks and selecting "run"
  8. Open a web browser and navigate to http://127.0.0.1:8001/tree/, which will show you a file browser at C:\. I recommend bookmarking this page, or navigating to a directory that you usually work under and then bookmark that page (I have http://127.0.0.1:8001/tree/Users/nbrown/Code bookmarked)

Conclusion

That's it! Now whenever you want a notebook just click your bookmark and away you go. All your notebooks will run on the same server, you can access them via the "Running" tab. If you are like me, you will accumulate quite a few running notebooks and only clear them out when you run out of memory. I find this far preferable to having to actively manage my Jupyter servers whenever I want a notebook.

Addendum: Jupyter Lab and The Future

The juyter notebook is slated to be replaced by jupyter lab which offers an exciting new workspace. As of this writing it is in alpha (0.6) but is already quite useful. I am writing this post with jupyter lab, making use of their markdown renderer to see my markdown rendered in real time as I type. You can use the same general techniques described above to set up an always-on jupyter lab server. Here are the necessary tweaks:

  • Run pip install -U jupyterlab. You might want to run this periodically as they are shipping new versions all the time.
  • Run jupyter serverextension enable --py jupyterlab --sys-prefix. This is required by the jupyter lab installation instructions.
  • Change the script passed to pythonw.exe ("Add arguments:" field in Scheduled Task Actions tab) to be the path to jupyter-lab.exe rather than jupyter-notebook.exe, which should be in the same <python install location>\Scripts\ folder.