Jupyter – Quick Guide

Jupyter – Quick Guide ”; Previous Next IPython – Introduction Project Jupyter is a suite of software products used in interactive computing. IPython was originally developed by Fernando Perez in 2001 as an enhanced Python interpreter. A web based interface to IPython terminal in the form of IPython notebook was introduced in 2011. In 2014, Project Jupyter started as a spin-off project from IPython. Packages under Jupyter project include − Jupyter notebook − A web based interface to programming environments of Python, Julia, R and many others QtConsole − Qt based terminal for Jupyter kernels similar to IPython nbviewer − Facility to share Jupyter notebooks JupyterLab − Modern web based integrated interface for all products. Standard distribution of Python comes with a REPL (Read-Evaluate-Print Loop) environment in the form of Python shell with >>> prompt. IPython (stands for Interactive Python) is an enhanced interactive environment for Python with many functionalities compared to the standard Python shell. Features of IPython IPython offers more features compared to the standard Python. They are as follows − Offers a powerful interactive Python shell. Acts as a main kernel for Jupyter notebook and other front end tools of Project Jupyter. Possesses object introspection ability. Introspection is the ability to check properties of an object during runtime. Syntax highlighting. Stores the history of interactions. Tab completion of keywords, variables and function names. Magic command system useful for controlling Python environment and performing OS tasks. Ability to be embedded in other Python programs. Provides access to Python debugger. History and Development IPython was originally developed by Fernando Perez in 2001. Its current version is IPython7.0.1 which requires Python 3.4 version or higher. IPython 6.0 was the first version to support Python 3. Users having Python 2.7 should work with IPython’s version 2.0 to 5.7 The concept of computational notebooks started in 80s decade when MATLAB and Mathematica were released. These GUI frontends to the interactive shell had features like text formatting, adding graphics, table and adding mathematical symbols. Sage notebook is also a web based notebook. Creaters of IPython started working on notebook interface for IPython shell in 2005. IPython notebook soon added support of other languages like R and Julia. It was in 2014, that Perez started Jupyter project as a spin-off project from IPython, since IPython project was becoming big with products like notebook server and Qt console added to it. Since IPython 4.0, all additional components were shifted to Project Jupyter and adding support of other languages to IPython notebook. IPython continues to focus on improvement of its enhanced interpreter feature. It also provides primary kernel to Jupyter notebook frontend. IPython – Installation IPython is included by default in Anaconda distribution of Python. It can be downloaded from Anaconda’s download page www.anaconda.com/download/ Binaries for all major OS (Windows, MacOS and Linux) and architecture (32 bit and 64 bit) are available on this link. To install IPython separately in standard Python installation, you can use pip command as shown below − pip3 install ipython IPython internally uses following packages − Sr.No. IPython dependencies & Functionality 1 colorama Cross-platform API for printing colored terminal text from Python 2 jedi An autocompletion tool for Python 3 pickleshare Small ‘shelve’ like datastore with concurrency support 4 prompt_toolkit Library for building powerful interactive command lines in Python 5 pygments Syntax highlighting package written in Python 6 simplegeneric Simple generic functions 7 traitlets Configuration system for Python applications. In general, all dependencies get installed automatically. Else, you can install them individually using pip. IPython – Getting Started This chapter will explain how to get started with working on IPython. Starting IPython from Command Prompt. Before proceeding to understand about IPython in depth, note that instead of the regular >>>, you will notice two major Python prompts as explained below − In[1] appears before any input expression. Out[1] appears before the Output appears. Besides, the numbers in the square brackets are incremented automatically. Observe the following screenshot for a better understanding − Now, if you have installed Anaconda distribution of Python, open Anaconda prompt from start menu. Start IPython from conda prompt When compared to regular Python console, we can notice a difference. The IPython shell shows syntax highlighting by using different colour scheme for different elements like expression, function, variable etc. Another useful enhancement is tab completion. We know that each object has one or more methods available as defined in its class. IPython pops up appropriate list of methods as you press tab key after dot in front of object. In the following example, a string is defined. As a response, the methods of string class are shown. IPython provides information of any object by putting ‘?’ in front of it. It includes docstring, function definitions and constructor details of class. For example to explore the string object var defined above, in the input prompt enter var?. The result will show all information about it. Observe the screenshot given below for a better understanding − Magic Functions IPython’s in-built magic functions are extremely powerful. There are two types of magic functions. Line magics, which work very much like DOS commands. Cell magics, which work on multiple lines of code. We shall learn about line magic functions and cell magic functions in detail in subsequent chapters. IPython – Running and Editing Python Script In this chapter, let us understand how to run and edit a Python script. Run Command You can use run command in the input prompt to run a Python script. The run command is actually line magic command and should actually be written as %run. However, the %automagic mode is always on by default, so you can omit this. In [1]: run hello.py Hello IPython Edit Command IPython also provides edit magic command. It invokes default editor of the operating system. You can open it through Windows Notepad editor and the script can be edited. Once you close it after saving its input, the output of modified script will be displayed. In [2]:

Jupyter – Useful Resources

Jupyter – Useful Resources ”; Previous Next The following resources contain additional information on Jupyter. Please use them to get more in-depth knowledge on this topic. Useful Video Courses Learn Hadoop and Spark analytics 13 Lectures 1 hours Pranjal Srivastava More Detail Basics Data Science with Numpy, Pandas and Matplotlib 11 Lectures 2.5 hours Akbar Khan More Detail Course on Jupyter Notebook – Big Data Visualization Tool 28 Lectures 55 mins Bigdata Engineer More Detail Survey of Python for GIS Applications 85 Lectures 13.5 hours Michael Miller More Detail GPT-3 : A Full Guide 22 Lectures 1.5 hours Vincent TERRASI More Detail Introducción a gráficas con Python y Jupyter Notebook 7 Lectures 1 hours Oscar Z More Detail Print Page Previous Next Advertisements ”;

JupyterLab – Installing R Kernel

JupyterLab – Installing R Kernel ”; Previous Next Project Jupyter now supports kernels of programming environments. We shall now see how to install R kernel in anaconda distribution. In Anaconda prompt window enter following command − conda install -c r r-essentials Now, from the launcher tab, choose R kernel to start a new notebook. The following is a screenshot of Jupyter notebook having R kernel − Print Page Previous Next Advertisements ”;

Installation & Getting Started

JupyterLab – Installation and Getting Started ”; Previous Next You can try online the features of JupyterLab before installing. Visit https://jupyter.org/try and choose ‘try JupyterLab’ option. The launcher tab shows currently available kernels and consoles. You can start a new notebook based/terminal based on any of them. The left column is also having tabs for file browser, running kernels and tabs and settings view. JupyterLab is normally installed automatically with Anaconda distribution. However, it can also be installed separately by using following conda command − conda install -c conda-forge jupyterlab You can also use the pip command for this purpose − pip3 install jupyterlab To start JupyterLab application, most convenient way is from Anaconda Navigator if it is installed. Alternately start it from command line from Windows/Linux command terminal or Anaconda prompt using this command − jupyter lab Either way, the JupyterLab application’s launch screen looks like this − Print Page Previous Next Advertisements ”;

JupyterLab – Interface

JupyterLab – Interface ”; Previous Next To start a new notebook, click the desired kernel. In above screenshot, one kernel is seen that is Python3 kernel. Click it to start a Python notebook. Observe that its functionality is similar to the one we have studied in this tutorial. Menu Bar The menu bar is at the top of window. The default menus you can find in this are − File − Actions related to files and directories. Edit − Actions related to editing documents and other activities. View − Actions that alter the appearance of JupyterLab. Run − Actions for running code in different activities such as notebooks and code consoles. Kernel − Actions for managing kernels, which are separate processes for running code. Tabs − A list of the open documents and activities in the dock panel. Settings − Common settings and an advanced settings editor. Help − A list of JupyterLab and kernel help links. The left sidebar shows buttons for starting a new launcher, adding a folder, uploading file and refresh file list. The right pane is the main working area where notebook, console and terminals are shown in tabbed view. To start a new console, click + symbol in the left side bar to open a new launcher and then click the console option. The console will open in new tab on the right pane. Note that the input cell is at the bottom, but when it is run, the cell and its corresponding output cell appears in upper part of console tab. The launcher also allows you open a text editor and a terminal in which IPython shell can be invoked. Print Page Previous Next Advertisements ”;

JupyterLab – Overview

JupyterLab – Overview ”; Previous Next Project Jupyter describes JupyterLab as a next generation web based user interfaces for all products under the Jupyter ecosystem. It enables you to work seamlessly with notebook, editors and terminals in an extensible manner. Some of the important features of JupyterLab are discussed below − Code Console acts as scratchpad for running code interactively. It has full support for rich output and can be linked to a notebook kernel to log notebook activity. Any text file (Markdown, Python, R, LaTeX, etc.) can be run interactively in any Jupyter kernel. Notebook cell output can be shown into its own tab, or along with the notebook, enabling simple dashboards with interactive controls backed by a kernel. Live editing of document reflects in other viewers such as editors or consoles. It is possible to have live preview of Markdown, Delimiter-separated Values, or Vega/Vega-Lite documents. JupyterLab can handle many file formats (images, CSV, JSON, Markdown, PDF etc.). It also displays rich output in these formats. JupyterLab provides customizable keyboard shortcuts uses key maps from many well-known text editors. Print Page Previous Next Advertisements ”;

Jupyter Notebook – IPyWidgets

Jupyter Notebook – IPyWidgets ”; Previous Next IPyWidgets is a Python library of HTML interactive widgets for Jupyter notebook. Each UI element in the library can respond to events and invokes specified event handler functions. They enhance the interactive feature of Jupyter notebook application. In order to incorporate widgets in the notebook, we have to import the following module as shown below − from ipywidgets import widgets Some basic IPyWidgets are explained here − Text input The widgets.text() function renders widgets in the notebook. It is similar to text box form element in HTML. The object of this widget has on_submit() method which listens to activity of the text field and can invoke event handler given as an argument to it. Button This widget is similar to HTML button. When it is clicked, the event is registered by on_click() method which calls the click event handler. IntSlider A slider control which displays the incrementing integer values. There is also a FloatSlider and IntRangeSlider (changing integer between a range) Label This widget is useful to display non editable text in the notebook. display() This function from ipywidgets module renders the widget object in notebook’s input cell. Interact This function automatically renders a widget depending upon type of data argument given to it. First argument to this function is the event handler and second is a value passed to event handler itself. Following example shows three label widgets, two text widgets and a button with ‘add’ caption. When the button is clicked, sum of numbers in two text input fields is displayed on the lowermost label. Print Page Previous Next Advertisements ”;

Jupyter – Discussion

Discuss Jupyter ”; Previous Next Project Jupyter is a comprehensive software suite for interactive computing, that includes various packages such as Jupyter Notebook, QtConsole, nbviewer, JupyterLab. This tutorial gives you an exhaustive knowledge on Project Jupyter. By the end of this tutorial, you will be able to apply its concepts into your software coding. Print Page Previous Next Advertisements ”;

Jupyter Notebook – Plotting

Jupyter Notebook – Plotting ”; Previous Next IPython kernel of Jupyter notebook is able to display plots of code in input cells. It works seamlessly with matplotlib library. The inline option with the %matplotlib magic function renders the plot out cell even if show() function of plot object is not called. The show() function causes the figure to be displayed below in[] cell without out[] with number. Now, add plt.show() at the end and run the cell again to see the difference. Note that the %matplotlib notebook magic renders interactive plot. Just below the figure, you can find a tool bar to switch views, pan, zoom and download options. Importantly, if you modify the data underneath the plot, the display changes dynamically without drawing another plot. In the above example, change the data sets of x and y in the cell below and plot the figure again, the figure above will get dynamically refreshed. Print Page Previous Next Advertisements ”;

QtConsole – Getting Started

Jupyter QtConsole – Getting Started ”; Previous Next In this chapter, let us understand how to get started with QtConsole. This chapter will give you an overview about this software and explains its installation steps. Overview The Qt console is a GUI application similar to IPython terminal. However, it provides a number of enhancements which are not available in text based IPython terminal. The enhance features are inline figures, multi-line editing with syntax highlighting, graphical calltips, etc. The Qt console can use any Jupyter kernel, default being IPython kernel. Installation Jupyter QtConsole is a part of Project Jupyter. Anaconda distribution is already having QTconsole application in it. In order to install it individually, use pip command as shown below − pip3 install qtconsole You can also use the conda command for this purpose − conda install qtconsole You can start Jupyter console from Anaconda navigator. To start it from the command line, you should use the following command, either from the Windows command prompt or Anaconda prompt − jupyter qtonsole You get a terminal similar to IPython terminal with first In[] prompt. You can now execute any Python expression exactly like we do in IPython terminal or Jupyter notebook Print Page Previous Next Advertisements ”;