Reader small image

You're reading from  Jupyter Cookbook

Product typeBook
Published inApr 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788839440
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Dan Toomey
Dan Toomey
author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey

Right arrow

Chapter 2. Adding an Engine

In this chapter, we will cover the following recipes:

  • Adding the Python 3 engine
  • Adding the R engine
  • Adding the Julia engine
  • Adding the JavaScript engine
  • Adding the Scala engine
  • Adding the Spark engine

Introduction


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.

Note

Each Notebook is expected to be written using one language per engine. There are some accommodations for mixing languages in one Notebook, but these are not expected to have a large amount of use.

Adding the Python 3 engine


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.

How to do it...

We will cover the installation of the Python 3 engine and make sure it is running with a script.

Installing the Python 3 engine

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...

Adding the R engine


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.

How to do it...

We can add the R engine to our Jupyter installation using Anaconda Navigator or the command line.

Installing the R engine using Anaconda Navigator

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...

Adding the Julia engine


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.

How to do it...

We will now cover the steps to add the Julia engine and execute a Julia script under Jupyter.

Installing the Julia engine

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...

Adding the JavaScript engine


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.

How to do it...

We will go over the steps to install the engine and run a small script.

Installing the Node.JS engine

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...

Adding the Scala engine


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.

How to do it...

We now go over the steps to install the Scala engine and run a Scala script.

Installing the Scala engine

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...

Adding the Spark engine


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.

How to do it...

We install the Spark engine and execute a Spark Jupyter script to show its working, as follows.

Installing the Spark engine

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...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Jupyter Cookbook
Published in: Apr 2018Publisher: PacktISBN-13: 9781788839440
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Dan Toomey

Dan Toomey has been developing application software for over 20 years. He has worked in a variety of industries and companies, in roles from sole contributor to VP/CTO-level. For the last few years, he has been contracting for companies in the eastern Massachusetts area. Dan has been contracting under Dan Toomey Software Corp. Dan has also written R for Data Science, Jupyter for Data Sciences, and the Jupyter Cookbook, all with Packt.
Read more about Dan Toomey