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.
Jupyter notebook is essentially a web server based browser-server program, which is developed with tornado framework. Below is it’s working sequence diagram.
Below is Jupyter notebook working process and some conclusion.
- User use web browser to interact with Jupyter notebook.
- Web browser interacts with the backend notebook web server over http and websocket protocol.
- Web server computes and communicates with the programming language kernel through ZMQ.
- Web server reads and writes the notebook file on hard disk.
- 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.
- 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.
- 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
- As a complete record of a session, notebook files interweave executable code, rich explanatory text, mathematical formulas, and result objects together.
- The notebook file is actually a JSON file, but is saved with the .ipynb extension.
- Because JSON is in plain text format, it can be viewed and shared with colleagues.
2. Install Jupyter Notebook.
Although Jupyter notebook supports multiple programming languages to run code, but 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.
2.1.1 Install Jupyter In Python3.
# First upgrade pip version. python3 -m pip install --upgrade pip # Install jupyter. python3 -m pip install jupyter
2.1.2 Install Jupyter In Python2.
python -m pip install --upgrade pip python -m pip install jupyter
2.2 Installing Jupyter Notebook Through Anaconda.
- Download the latest version of Anaconda.
- Install Anaconda according to the installation wizard.
- If everything is correct, open the terminal in Mac / Linux, or open the command line interface in Windows, and run command jupyter notebook.
- 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.
After install, you can run 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 http://127.0.0.1:8888/?token=baff2b5d3a5a55298320732d5974a1582c60c3d33e92750d [I 13:32:51.033 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
It will also open a default web browser and display the jupyter home page ( http://localhost:8888/tree ). The home page is like below picture. The currently displayed directory is the working directory of your notebook server, which can be configured.
Below are some useful command tips when start jupyter.
- Open the specified notebook file.
jupyter notebook notebook.ipynb
- Specify the jupyter notebook web server port number.
jupyter notebook --port 9999
- Start jupyter notebook web server without opening the browser.
jupyter notebook --no-browser
- View jupyter notebook server help.
jupyter notebook --help