Skip to content

Instantly share code, notes, and snippets.

@NickRSearcy
Last active September 7, 2018 01:29
Show Gist options
  • Save NickRSearcy/c46771d83a3168481eee to your computer and use it in GitHub Desktop.
Save NickRSearcy/c46771d83a3168481eee to your computer and use it in GitHub Desktop.
How to use Jupyter for general-purpose academic coding

What is Jupyter?

The most important part of Jupyter for our purposes is the Notebook, a tool for developing and documenting code across a variety of languages. Take a moment and check out a gallery of fantastic notebooks to get an idea of what it is used for.

How to get Jupyter

All users can install Jupyter according to the installation instructions in the Jupyter documentation. I will refer to this as the "Anaconda method" because that is the package manager recommended in the official documentation. This should work smoothly, especially if you primarily intend to use Python in Jupyter.

However, for Mac users, I would recommend an alternative installation method (the "Homebrew method") that should make it easier to support alternative languages.

Installation via the Homebrew method

Again, if you want the simplest installtion method, or if you have already tried this one and it failed, I would recommend the official Jupyter instructions above. The instructions that follow should make it easier to configure Jupyter to support other languages. And they only apply to Mac.

First, install homebrew. Open a terminal (type ⌘-space and then 'terminal') and enter the single line listed on the home page. This is a package manager for Mac computers, it allows you to install, upgrade, and manage software on Mac.

Second, install Python (we will use python 3.5) with (type this into your terminal and hit return):

brew install python3

Now you have Python installed. You can start a python shell whenever you would like by entering python3 in your terminal (close the shell with quit()). This also installed pip which is a package manager specifically for Python. We will use pip to install jupyter with the following:

pip3 install jupyter -U

Now you have Jupyter installed. You can check that everything is working with jupyter notebook which should start the application locally and open a page in your browser. This starts a server that runs on your local machine. You can close this server by hitting control-C twice.

Using other languages with Jupyter

Other languages are supported in Jupyter via what is called a "kernel". The Python kernel is automatically installed with Jupyter. Here's the full list of supported kernels. You should be warned that here, "supported" is used somewhat loosely and that the degree of support varies in that list from proof-of-concept to stable.

Here I'm going to show you how to get the R kernel working on a Mac, assuming you installed via the Homebrew method. If you used the Anaconda method, you may install Homebrew only according to the Homebrew method but skip the steps installing Jupyter (you don't want to install it a second time) then proceed here.

Install R with homebrew using the following in a terminal:

brew tap homebrew/science
brew install r

Once that is completed, you can open up an R console with r (yes, literally typing the single letter r into a terminal and hitting enter). You can close the console with quit(). Using such an R console, follow the instructions on the IRKernel installation page.

You should then be able to close any Jupyter servers you have open (by hitting control-C twice in the terminal), reopen them and find R listed in the available kernels under "new" in the top-right corner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment