Open ipython notebook on existing notebook server

2019-04-13 08:28发布

问题:

I'm seeking a way to open ipynb file on an existing notebook server.

There is a notebook server on my home directory started as follows:

/home/myname$ ipython notebook

And I have a notebook file /home/myname/work_dir/test.ipynb. I need a script to open this file on the notebook:

cd work_dir
ipynb_open test.ipynb  # No such command!

I know that I can open this ipynb on a new notebook server by the following command:

ipython notebook test.ipynb

But this command stands a new server, and I have to kill this server by hands.

In this case, since I know the directory where the notebook is executed, I can open test.ipynb by directly specifying its relative path:

open http://localhost:8888/node/work_dir/test.ipynb

But I want to resolve this address automatically.

Reading documents, I found an option --existing, but following command does not work.

ipython notebook --exsiting test.ipynb

So my questions are:

  • Is there a command corresponding to ipynb_open noted above?
  • Is there a way to gather information about running notebook servers?

回答1:

Say hello to nbopen, which does exactly this!

https://github.com/takluyver/nbopen

Running notebook servers write JSON files to disk with their information; there's a Python function notebook.notebookapp.list_running_servers() that iterates over the running servers, and this is what nbopen uses.

Nbopen also includes desktop integration so you can double-click on a .ipynb file to open it. But you can install the nbopen command without the desktop integration if you prefer.