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
$43.99
Book Apr 2018 238 pages 1st Edition
eBook
$35.99 $24.99
Print
$43.99
Subscription
$15.99 Monthly
eBook
$35.99 $24.99
Print
$43.99
Subscription
$15.99 Monthly

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela