Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Jupyter Cookbook
Jupyter Cookbook

Jupyter Cookbook: Over 75 recipes to perform interactive computing across Python, R, Scala, Spark, JavaScript, and more

By Dan Toomey
€25.99 €17.99
Book Apr 2018 238 pages 1st Edition
eBook
€25.99 €17.99
Print
€32.99
Subscription
€14.99 Monthly
eBook
€25.99 €17.99
Print
€32.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Apr 30, 2018
Length 238 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781788839440
Category :
Concepts :
Table of content icon View table of contents Preview book icon Preview Book

Jupyter Cookbook

Chapter 1. Installation and Setting up the Environment

In this chapter, we will cover the following recipes:

  • Installing Jupyter on Windows
  • Installing Jupyter on the Mac
  • Installing Jupyter on Linux
  • Installing Jupyter on a server

Introduction


We will see how to install Jupyter on different environments. We will install it on Windows, the Mac, Linux, and a server machine. Some consideration should be given to multiple user access when installing on a server. If you are going to install it on a non-Windows environment, please review the Anaconda installation on Windows first as the same installation steps for Anaconda are available on other environments.

Installing Jupyter on Windows


The Windows environment suffers from a drawback: none of the standard Linux tools are available out of the box. This is a problem as Jupyter and many other programs were developed on a version of Unix and expect many developer tools normally used in Unix to be available.

Getting ready

Luckily, there is a company that has seen this problem and addressed it—Anaconda. Anaconda describes itself as a Python Data Science Platform, but its platform allows for a variety of solutions in data science that are not based on Python.

How to do it...

After installing Anaconda and starting Navigator, you get to a dashboard that presents the programs available, such as:

The Anaconda Navigator provides access to each of the programs you have installed (using Anaconda). Each of the programs can be started from Navigator (by clicking on the associated Launch button) and you can also start them individually (as they are standalone applications). As you install programs with Anaconda, additional menu items become available under the Anaconda menu tree for each of the applications to run directly. The menu item has coding to start the individual applications as needed.

As you can see in the preceding screen, the Home display shows the applications available. There are additional menu choices for:

  • Environments: This menu displays all the Python packages that have been installed. I don't think R packages are displayed, nor are other tools or packages included in this display.
  • Projects (beta): This menu is usually empty. I have been using/upgrading Anaconda for a while and have not seen anything displayed here.
  • Learning: This is a very useful feature, where a number of tutorials, videos, and write-ups have been included for the different applications that you (may) have installed.
  • Community: This lists some community groups for the different products you have installed.

The preceding screen shows Jupyter as an installed program. The standard install of Anaconda does include Jupyter. If you choose not to use Anaconda, you can install Jupyter directly.

Installing Jupyter directly

Jupyter, as a project, grew out of Python, so it is somewhat dependent on which version of Python you have installed. For Python 2 installations, the command line steps to install Jupyter are:

python -m pip install --upgrade pip
python -m pip install jupyter

This assumes you have pip installed. The pip system is a package management system written in Python. To install pip on your Windows machine, execute the following line:

python get-pip.py

As you can see, this is all Python (this code calls Python to execute a standard Python script).

Installing Jupyter through Anaconda

Anaconda provides the tools to install a number of programs, including Jupyter. Once you have installed Anaconda, Jupyter will be available to you already.

The only issue I found was that the engine installed was Python 2 instead of Python 3. There is a process that Anaconda uses to decide which version of Python to run on your machine. In my case, I started out with Python 2. To upgrade to Python 3, I used these 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 might be if you want to use scripts that were written using Python 2. The commands to add Python 2 back in as an engine choice are:

python2 -m pip install ipykernel 
python2 -m ipykernel install --user

You should now see Python 2 and Python 3 as engine choices when you start Jupyter:

Installing Jupyter on the Mac


Apple Macintosh provides a graphical interface that runs on the OS/X operating system. OS/X includes running BSD under the hood. BSD is a version of Unix originally developed at Berkeley. As a version of Unix, it has all the standard developer tools expected by Jupyter to install and upgrade the software; they are built-in tools.

Getting ready

Jupyter can be installed on the Mac using Anaconda (as before for Windows) or via the command line.

How to do it...

In this section, we will go through the steps for installing Jupyter on Mac.

Installing Jupyter on the Mac via Anaconda

Just as with Windows earlier, we download the latest version of Anaconda and run the installation program. One of the screens should look like this:

The Anaconda install is very typical for Mac installs: users can run the program and make sure they want to allocate so much storage for the application to install. 

Once installed, Jupyter (and Anaconda Navigator) is available just like any other application on the system. You can run Jupyter directly, or you can launch Jupyter from the Anaconda Navigator display.

Installing Jupyter on the the Mac via the command line

Many Mac users will prefer using the command line to install Jupyter. Using the command line, you can decide whether to install Jupyter with the Python 2 or Python 3 engine. If you want to add the Python 2 engine as a choice in Jupyter, you can follow similar steps for doing so in the earlier Windows command line installation section.

The script to install Jupyter on Mac via the command line with the Python 3 engine is:

bash ~/Downloads/Anaconda3-5.0.0-MacOSX-x86_64.sh

Similarly, the command to install with the Python 2 engine is as follows:

bash ~/Downloads/Anaconda2-5.0.0-MacOSX-x86_64.sh

In either case, you will be prompted by some regular install questions:

  • Review and agree to the license agreement
  • Specify whether the standard install directory is OK (if not, you can specify where to install the software)
  • Specify whether to prepend the Anaconda location in your user path (Anaconda recommends this step)

At this point, you should be able to start Jupyter with the command line and see the appropriate engine choice available:

jupyter notebook

Installing Jupyter on Linux


Linux is one of the easier installations for Jupyter. Linux has all the tools required to update Jupyter going forward. For Linux, we use similar commands to those shown earlier to install on the Mac from the command line. 

How to do it...

Linux is a very common platform for most programming tasks. Many of the tools used in programming have been developed on Linux and later ported to other operating systems, such as Windows.

Note

We are using Anaconda to install on Linux, but the graphical interface is not available.

The script to install Jupyter on Linux via the command line with the Python 3 engine is:

bash ~/Downloads/Anaconda3-5.0.0.1-Linux-x86_64.sh

Similarly, the command to install with the Python 2 engine is:

bash ~/Downloads/Anaconda2-5.0.0.1-Linux-x86_64.sh

In either case, you will be prompted by some regular install questions:

  • Review and agree to the license agreement
  • Specify whether the standard install directory is OK (if not, you can specify where to install the software)
  • Specify whether to prepend the Anaconda location in your user path (Anaconda recommends this step)

And, as shown earlier under specify Windows and Mac installation sections, you can have the Python 2 and Python 3 engines available using similar steps.

At this point, you should be able to start Anaconda Navigator with the command line:

anaconda-navigator

Or you can run Jupyter directly using the regular command line:

jupyter notebook

Installing Jupyter on a server


The term server has changed over time to mean several things. We are interested in a machine that will have multiple users accessing the same software concurrently. Jupyter Notebooks can be run by multiple users. However, there is no facility to separate the data for one user from another. Standard Jupyter installations only expect and account for one user. If we have a Notebook that allows for data input from the user, then the data from different users will be intermingled in one instance and possibly displayed incorrectly.

How to do it...

See the following example in this section.

Example Notebook with a user data collision

We can see an example of a collision with a Notebook that allows for data entry from a user and responds with incorrect results:

  • I call upon an example that I have used elsewhere for illustration. For this example, we will use a simple Notebook that asks the user for some information and changes the display to use that information:
from ipywidgets import interact
def myfunction(x):
    return x
interact(myfunction, x= "Hello World ");
  • The script presents a textbox to the user, with the original value of the box containing the Hello World string.
  • As the user interacts with the input field and changes the value, the value of the variable x in the script changes accordingly and is displayed on screen. For example, I have changed the value to the letter A:
  • We can see the multiuser problem if we open the same page in another browser window (copy the URL, open a new browser window, paste in the URL, and hit Enter). We get the exact same display—which is incorrect. We expected the new window to start with a new script, just prompting us with the default Hello World message. However, since the Jupyter software expects only one user, there is only one copy of the variable x; thus, it displays its value A.

We can have a Notebook server that expects multiple users and separates their instances from each other without the annoying collisions occurring. A Notebook server includes the standard Jupyter Notebook application that we have seen, but a server can also include software to distinguish the data of one user from another. We'll cover several examples of this solution in Chapter 8, Multiuser Environments.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Create and share interactive documents with live code, text and visualizations
  • Integrate popular programming languages such as Python, R, Julia, Scala with Jupyter
  • Develop your widgets and interactive dashboards with these innovative recipes

Description

Jupyter has garnered a strong interest in the data science community of late, as it makes common data processing and analysis tasks much simpler. This book is for data science professionals who want to master various tasks related to Jupyter to create efficient, easy-to-share, scientific applications. The book starts with recipes on installing and running the Jupyter Notebook system on various platforms and configuring the various packages that can be used with it. You will then see how you can implement different programming languages and frameworks, such as Python, R, Julia, JavaScript, Scala, and Spark on your Jupyter Notebook. This book contains intuitive recipes on building interactive widgets to manipulate and visualize data in real time, sharing your code, creating a multi-user environment, and organizing your notebook. You will then get hands-on experience with Jupyter Labs, microservices, and deploying them on the web. By the end of this book, you will have taken your knowledge of Jupyter to the next level to perform all key tasks associated with it.

What you will learn

Install Jupyter and configure engines for Python, R, Scala and more Access and retrieve data on Jupyter Notebooks Create interactive visualizations and dashboards for different scenarios Convert and share your dynamic codes using HTML, JavaScript, Docker, and more Create custom user data interactions using various Jupyter widgets Manage user authentication and file permissions Interact with Big Data to perform numerical computing and statistical modeling Get familiar with Jupyter s next-gen user interface - JupyterLab

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Apr 30, 2018
Length 238 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781788839440
Category :
Concepts :

Table of Contents

17 Chapters
Title Page Chevron down icon Chevron up icon
Copyright and Credits Chevron down icon Chevron up icon
Packt Upsell Chevron down icon Chevron up icon
Contributors Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
Installation and Setting up the Environment Chevron down icon Chevron up icon
Adding an Engine Chevron down icon Chevron up icon
Accessing and Retrieving Data Chevron down icon Chevron up icon
Visualizing Your Analytics Chevron down icon Chevron up icon
Working with Widgets Chevron down icon Chevron up icon
Jupyter Dashboards Chevron down icon Chevron up icon
Sharing Your Code Chevron down icon Chevron up icon
Multiuser Jupyter Chevron down icon Chevron up icon
Interacting with Big Data Chevron down icon Chevron up icon
Jupyter Security Chevron down icon Chevron up icon
Jupyter Labs Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.