How To Use Jupyter Notebook Tutorial

Jupyter notebook is a web application program. It can be used to easily create and share program documents. It supports real-time code, mathematical equations, visualization, and markdown. It’s purpose includes data cleaning and conversion, numerical simulation, statistical modeling, machine learning, etc. This article will tell you how to install and run it.

1. Jupyter Notebook Operating Mechanism.

  1. Jupyter notebook is essentially a web server based browser-server program, which is developed with the tornado framework. Below is it’s working sequence diagram.
  2. Below is the Jupyter notebook working process and some conclusions.
  3. Users use a web browser to interact with Jupyter notebook.
  4. Web browser interacts with the backend notebook web server over HTTP and WebSocket protocol.
  5. Web server computes and communicates with the programming language kernel through ZMQ.
  6. Web server reads and writes the notebook file on the hard disk.
  7. The web server maintains a readable and writable browser-based editing environment and storage service. The kernel is only used to execute specific code and return results.
  8. The kernel here is not limited to Python, it can be more than 40 languages such as R language. The coding language in which the notebook file you are currently editing is linked to the interpreter kernel for that coding language.
  9. You can list currently used kernels with command jupyter kernelspec list in terminal like below.
    $ jupyter kernelspec list
    Available kernels:
      python3    /Users/songzhao/opt/anaconda3/share/jupyter/kernels/python3
  10. As a complete record of a session, notebook files interweave executable code, rich explanatory text, mathematical formulas, and result objects together.
  11. The notebook file is actually a JSON file but is saved with the .ipynb extension.
  12. Because JSON is in plain text format, it can be viewed and shared with colleagues.

2. Install Jupyter Notebook.

  1. Although Jupyter notebook supports multiple programming languages to run code, it requires python (Python 3.3 or later, or Python 2.7) to install it. There are two methods to install it.

2.1. Install Jupyter Use PIP.

  1. Install Jupyter In Python3.
    # First upgrade pip version.
    python3 -m pip install --upgrade pip
    # Install jupyter.
    python3 -m pip install jupyter
  2. Install Jupyter In Python2.
    python -m pip install --upgrade pip
    python -m pip install jupyter

2.2 Installing Jupyter Notebook Through Anaconda.

  1. Download the latest version of Anaconda.
  2. Install Anaconda according to the installation wizard.
  3. If everything is correct, open the terminal in Mac / Linux, or open the command-line interface in Windows, and run the command jupyter notebook.
  4. Because of the problem of system path, sometimes you will be prompted that it cannot find the executable command. Please add the path of the jupyter script or executable to your system path variable to fix this issue.

3. Start Jupyter Notebook.

  1. After install, you can run the command jupyter notebook to start it, you can see output like below.
    $ jupyter notebook
    [I 13:32:51.030 NotebookApp] JupyterLab extension loaded from /Users/songzhao/opt/anaconda3/lib/python3.7/site-packages/jupyterlab
    [I 13:32:51.030 NotebookApp] JupyterLab application directory is /Users/songzhao/opt/anaconda3/share/jupyter/lab
    [I 13:32:51.033 NotebookApp] Serving notebooks from local directory: /Users/songzhao
    [I 13:32:51.033 NotebookApp] The Jupyter Notebook is running at:
    [I 13:32:51.033 NotebookApp] http://localhost:8888/?token=baff2b5d3a5a55298320732d5974a1582c60c3d33e92750d
    [I 13:32:51.033 NotebookApp]  or
    [I 13:32:51.033 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
  2. It will also open a default web browser and display the jupyter home page ( http://localhost:8888/tree ).
  3. The currently displayed directory on the home page is the working directory of your notebook server, which can be configured.
  4. Below are some useful command tips when starting jupyter notebook.
  5. Open the specified notebook file.
    jupyter notebook notebook.ipynb
  6. Specify the jupyter notebook webserver port number.
    jupyter notebook --port 9999
  7. Start jupyter notebook web server without opening the browser.
    jupyter notebook --no-browser
  8. View jupyter notebook server help.
    jupyter notebook --help

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.