Jupyter integration with emacs

I had a few difficulties installing it, so maybe this write-up will be all the more useful.

Here is how things go if everything works well:

  1. Installation:

    1. Install IJulia:

       julia> using Pkg
       julia> Pkg.add("IJulia")
       julia> using IJulia
       julia> notebook()  # will install Jupyter the first time
       # Shutdown the notebook from the browser before quitting
       # the REPL
      
    2. Install the jupyter package from ELPA:

      M-x package-install RET jupyter RET

  2. Usage:

    1. Run a Julia REPL:

      M-x jupyter-run-repl RET

    2. Associate jour julia buffer(s) to the kernel:

      M-x jupyter-repl-associate-buffer RET

    3. You’re good to go, and benefit from a few features, among which:

      • C-M-x: evaluate the defun at point
      • C-cC-c: evaluate the line/region at point
      • C-cC-b: evaluate the whole buffer
      • M-i: get help for the thing at point

Here is what a small example session looks like:

  • I evaluated the function first using C-M-x
  • then the hello() call in the file using C-cC-c; this opened the “output” window at the bottom right
  • I manually typed hello() in the REPL (top right wndow)
  • I pressed M-i with point on println; this opened the bottom left help window.




Now, here are the issues I had:

  • “Modules are not supported” at step 2: this is because your Emacs should support dynamic modules. It wasn’t the case for my out-of-the-box Emacs version on Debian and I had to manually rebuild and reinstall an Emacs version configured using --with-modules.

  • “No kernelspecs available” at step 2: if, like me, you let IJulia install jupyter automagically for you, chances are that the jupyter command is not in your PATH. You’ll have to add the correct jupyter installation directory to your PATH for Emacs to be able to find it.

    • first, determine the correct directory by running a notebook:

        julia> using IJulia
        julia> notebook()
        [ Info: running setenv(`/home/francois/.julia/conda/3/bin/jupyter notebook`,["PATH=
        /home/francois/.julia/conda/3/bin:/home/francois/.scripts:/home/francois/.local/bin
        :/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/francois/.local/jul
        ia-1.1.0/bin/:/home/francois/projets/git/skeleton.jl/:/home/francois/.local/julia-1
        .1.0/bin/:/home/francois/projets/git/skeleton.jl/", ...
        ...])                               
      

      In this case, the directory we’re looking for is:
      /home/francois/.julia/conda/3/bin

    • then, add this directory to your PATH, either from your .bashrc file (or equivalent for your shell), or directly from Emacs:

        (setenv "PATH"
                (concat "/home/francois/.julia/conda/3/bin:" 
                        (getenv "PATH")))
      
13 Likes