At Long Last, a Good Julia Setup
I was inspired to write this post because I’ve been programming Julia for the last year, and only now have I found a setup that I like. This is partly because I am on NixOS, and partly because I like emacs, so you may very well already have a nice Julia setup and in that case can ignore this. But for those of you who are slightly unsatisfied… read on!
The key ingredients are docker, jupyter, and doom-emacs.
First off, I have a docker file that looks like this:
FROM julia:1.5
MAINTAINER Owen Lynch <root@owenlynch.org>
RUN apt-get update && apt-get install texlive-full graphviz -y
RUN apt-get update && apt-get install at-spi2-core libgtk-3-dev xauth xvfb libqt5widgets5 -y
ENV PATH=/root/.julia/conda/3/bin:$PATH
Periodically I add more packages to this; I don’t particularly remember why I needed all of those packages but whatever.
I then run this docker container with bind mounts for everything in the root folder. This means that I don’t have to reinstall packages every time I restart the docker container. My script to open up a bash shell in the container looks like this
#!/usr/bin/env bash
docker run -it -p 8888:8888 -v /home/o/g:/g -v /home/o/s/docker-julia-home:/root julia-tex bash
When I first set up the container, I run this script to go into a bash shell, and I open a Julia REPL to install IJulia. This installs conda and Jupyter for me automatically, which is nice because then python dependencies are also managed through Julia. I love Nix, but Julia just does not play nicely with it, so I’ve found it’s best to just give Julia free reign to do whatever it wants to a docker container.
Once I’ve installed IJulia and Jupyter, I close the bash shell, and run this
#!/usr/bin/env bash
docker run -it -p 8888:8888 -v /home/o/g:/g -v /home/o/s/docker-julia-home:/root julia /root/.julia/conda/3/bin/jupyter lab --ip=0.0.0.0 --allow-root
At this point, you can access the jupyter lab through a webbrowser at localhost:8888
, which is convenient. However, this doesn’t stop there!
The next step is emacs-jupyter. I have this installed through doom emacs with the layer (org +jupyter)
, you may have a better way of installing it. I don’t really use it with org mode most of the time so… *shrug*.
Anyways, once this is installed, I run the command jupyter-run-server-repl
and then pass in the connection details for the Jupyter server in docker to the prompts. This opens a repl in Emacs that has support for inline images, which is really nice for plots. Finally, I open up a Julia file and run jupyter-repl-associate-buffer
. This allows me to use key combinations like C-c C-c
to evaluate a region, or C-c C-b
to evaluate the whole buffer.
And that’s pretty much it! This will allow you to use Julia in emacs without permanently installing anything on your computer, and should work well anywhere where docker bind mounts work. In the future, I might look into running PackageCompiler to get Jupyter kernels that load IJulia and Plots faster, but I’m not going to worry about that yet.
This setup should also work with Python and R, but I haven’t used it very much for that, so YMMV.