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!



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.


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

For people seeing this now: In the meantime UTop got a pretty neat vi editing mode, too. So no need to switch to Jupyter for that reason anymore.


I use emacs, and sometimes utop.
I prefer emacs over utop, and I guess that jupyter will
have troubles being superior in any way to emacs given the long evolutionary process Emacs has undergone…

1 Like

Did anybody have issues when installing kernelspec?

➜  ~ jupyter kernelspec install --name ocaml-jupyter "$(opam var share)/jupyter" --user                                                       4.12.1+flambda
[InstallKernelSpec] Removing existing kernelspec in /home/kakadu/.local/share/jupyter/kernels/ocaml-jupyter
[InstallKernelSpec] Installed kernelspec ocaml-jupyter in /home/kakadu/.local/share/jupyter/kernels/ocaml-jupyter
➜  ~ jupyter kernelspec list                                                                                                                  4.12.1+flambda
Available kernels:
  python2    /home/kakadu/.local/share/jupyter/kernels/python2
  python3    /home/kakadu/.local/share/jupyter/kernels/python3