Setup Jupyter with Py 2, 3, and R
Jupyter Notebook is a great tool for teaching code and exploratory, iterative coding. It was originally developed for Python, but it now supports a variety of kernels. Notebook becomes even more useful with both Python 2 and 3 installed (keep in mind Python 3 is current, 2 is legacy). And you may as well add R while you’re at it!
1. Install Jupyter via Anaconda
First, Jupyter project and I suggest you install Python 3 via the Anaconda distribution. Conda gives you a huge package of scientific Python libraries pre-installed, plus some very handy management and virtual environment tools. Once you install Anaconda Python 3, you automagically have Jupyter with the IPython3 kernel ready to go.
If you already have Anaconda installed, be sure to update before adding the additional kernels, using
conda update conda.
2. Add Python 2 kernel to Jupyter
Second, add the Python 2 kernel using a virtual environment:
- open a terminal and create a new Python 2 environment:
conda create -n py27 python=2.7
- activate the environment: linux
source activate py27or windows
- install the kernel in the env:
conda install notebook ipykernel
- install the kernel for outside the env:
ipython kernel install --user
- close the env:
3. Add R kernel to Jupyter
Third, we add R via Conda. Conda R-essentials includes a bunch of popular R packages, including the Notebook IRKernel.
Simply open a terminal and install R and R-essentials:
conda install -c r r-essentials
Open a terminal and type:
The Notebook interface will open in your browser (ignore the server back end running in the terminal). On the right side of the Notebook, click the “New” button. You should have the options for Python [default] (i.e. conda py 3), Python 2, and R. Pretty handy for teaching and learning!
To shut down Jupyter, close the browser window, then
Ctrl + C in the terminal host.
Add more Jupyter stuff
Conda has a few other addons available for Jupyter. Check the documentation to learn more.
Notebooks are gaining attention for integrating code and publication, opening possibilities for interactive sharing and visualization.
- SageMath (math focused notebook platform, an “open source alternative to Magma, Maple, Mathematica, and MATLAB”. A solid project that has been around for awhile, but hasn’t gained much popularity.)
- Apache Zepplin (Java based notebook particularly useful for dashboards and Spark cluster integration, i.e. big data)
- Beaker notebook (newish project, multiple languages in a single notebook)