Jupyter -- a better UTop?

I recently figured out how to get an alternative REPL which has some things that UTop doesn’t. It’s the Jupyter console, which runs in a terminal (and is less well-known than the Jupyter notebook).

Here’s how to set it up:

  • install jupyter by a method that works for your OS.
  • opam install jupyter
  • set up ocaml as a kernel for jupyter, as explained in the package doc: jupyter kernelspec install --name ocaml-jupyter "$(opam config var share)/jupyter"
  • in jupyter kernelspec list find the new kernel directory and edit the JSON file there, for instance to include a custom .ocamlinit. In mine I added #use topfind;;
  • enable vi edit mode by echo "c.ZMQTerminalInteractiveShell.editing_mode='vi'" >> ~/.jupyter/jupyter_console_config.py (entirely non optional :wink: )

Then start your new REPL by jupyter console --kernel=ocaml-jupyter. Thanks to the cool ocaml jupyter package, it will use Merlin to autocomplete, it will let you browse history in the usual jupyter way, and it will have a vi_mode !
You can also use various editor plugins to send code cells to the ocaml-jupyter kernel directly from an editing buffer. Right now, this solution is missing the UTop.set_create_implicits automatic binding of previous outputs, but that is not a huge problem. Overall, pretty neat in my book!

11 Likes

Interesting!

As a (k)ubuntu linux user at least, I had to add --user to step #3 to avoid running as sudo. I also had to manually create the ~/.jupyter directory before running the echo command.

3 Likes

Thank you very much for this hint. I find utop very hard to use without vi keys.