You're reading from Jupyter Cookbook
Jupyter provides the ability to use a variety of languages when developing a Notebook. Each of the languages is supported through the use of an engine that provides all of the programmatic interface from the coded language instruction that you write with the underlying Notebook. Several of the popular languages in use are Python, R, Julia, JavaScript, and Scala. In this chapter, we will show you the steps to add these engines to your Jupyter installation so that you can script your Notebook in the language you like.
Jupyter was originally derived from Python with the IPython project. At that time, Python 2 was the predominant version available for use. For every installation of Jupyter, the default engine provided is Python 2. There are a number of changes involved when moving from Python 2 to Python 3, especially in the underlying libraries that you may be invoking, where parameter and usage changes have occurred.
We will cover the installation of the Python 3 engine and make sure it is running with a script.
Assuming you have installed the standard Jupyter package, you now have Python 2 as the only engine available at the top of the Jupyter portal screen:
To upgrade to Python 3, I used the commands:
conda create -n py3k python=3 anaconda source activate py3k ipython kernelspec install-self
After this, when you start Jupyter, you will have the Python 3 engine choice.
You may prefer to have the Python 2 engine also available. This could...
R is both a programming language and a software environment geared toward statistical computing and associated graphics. R has a clean syntax, providing access to a large set of statistical packages, publicly available for free use.
We can add the R engine to our Jupyter installation using Anaconda Navigator or the command line.
R is included with the R Studio option in Anaconda Navigator, as shown in this partial screenshot:
As noted in the screen, the R Studio installation includes R essentials and Notebooks (Notebook engine support).
Note
This screenshot shows R after it has been installed (see the Launch
button). Whereas before it is installed, the rstudio graphic icon will display in Anaconda Navigator with an Install
button.
Once you select the Install
button, Anaconda will automatically install R in your environment and bring you back to the Navigator screen, now showing the Launch
button as shown in the...
Julia is a high-level programming language. It was built with high performance in mind, especially with regard to numerical computing. As such, it is a custom-made language for data science use.
We will now cover the steps to add the Julia engine and execute a Julia script under Jupyter.
I know that in previous instances of Jupyter, Julia was automatically installed as an engine in non-Windows environments. I do not have access to another environment, so we will walk through the steps to installing Julia on Windows.
The first step is to download and install the appropriate version from the Julia downloads page, https://julialang.org/downloads. I noticed that there are installs available for macOS and Linux from this page as well. In my case, I could use the 64-bit self-extracting executable. Once installed, we can start the Julia environment, which has a splash screen like this:
Now that Julia is installed, we can request the...
JavaScript is another engine that can be used with Jupyter. Actually, it is node.js
rather than JavaScript. node.js
is a superset of JavaScript. node.js
is an extension of JavaScript that is expected to be run on a server. As with JavaScript, node.js
is cross-platform.
We will go over the steps to install the engine and run a small script.
First, we need to install node.js
. It is available from node.js.org
. From this site, you can download and install node.js
on your machine directly. The installer for Windows is a standard design that looks similar for other environments.
Next, we need to install the JavaScript engine, ijavascript
. We use the npm
tool (installed with node.js
) to install ijavascript
with the command:
npm install -g ijavascript
The non-Windows running of this script is within sudo
(the run
command as a superuser), so I think the equivalent would be to run this script from a command window that is run as administrator...
Scala is described as a general-use language that is concise and elegant. Scala is an extension of the Java language and can call upon Java libraries. Its syntax is very similar as well.
We now go over the steps to install the Scala engine and run a Scala script.
The Scala engine implementation is immature. There may be better installations available for non-Windows environments, but for Windows I followed the following instructions, where someone had built a version of the Scala engine for Windows that you can add to your environment.
At the bottom of this issue on the Jupyter Scala board at https://github.com/jupyter-scala/jupyter-scala/issues/108, there is a link to the code that you can use. At the bottom of that issue is the actual link: https://github.com/jupyter-scala/jupyter-scala/issues/1#issuecomment-315643483. Here, someone has set up a Scala engine for Windows to download at https://github.com/rvilla87/Big-Data/raw...
Spark is an Apache project that provides an open source computing framework specially geared toward cluster computing. For our purposes, it provides a language called Spark that can be used to access Hadoop information sets.
We install the Spark engine and execute a Spark Jupyter script to show its working, as follows.
Generally, installing Spark involves two steps:
- Installing Spark (for your environment)
- Connecting Spark to your environment (whether standalone or clustered)
The Spark installations are environment specific. I've included the steps to install Spark (in connection with Jupyter) for a Windows environment here. There are different instructions for other environments.
Similarly, Spark relies on a base language to work from. This can be Scala or Python. We automatically have Python as part of the Jupyter installations, so we will rely on Python as the basis. In other words, we will code a Python Notebook, where Python...