How To Use IPython Jupyter Notebook To Develop Python Code

IPython is an enhanced Python interactive environment, you can run all Python source code in IPython. And it provides more features that make your development process easy. Jupyter notebook is a browser-server based website tool that can save your python source code in a .ipynb notebook file, and then when you submit the python source code to your local Jupyter web server, it will start an iPython kernel to run the source code, and then display the result or error messages just below your python source code in the web page for interactive development. This article will introduce how to use iPython and Jupyter notebook to develop interactive python source code with examples.

1. Install IPython.

  1. Before installing IPython, you can run the command $ pip3 show ipython to check whether it has been installed or not. This command will show it’s version and installation directory.
    (base) :~$ pip3 show ipython
    Name: ipython
    Version: 7.3.0
    Summary: IPython: Productive Interactive Computing
    Home-page: https://ipython.org
    Author: The IPython Development Team
    Author-email: [email protected]
    License: BSD
    Location: /home/zhaosong/.local/lib/python3.6/site-packages
    Requires: pexpect, decorator, pickleshare, jedi, prompt-toolkit, backcall, pygments, traitlets, setuptools
  2. If you do not install IPython, run $ pip3 install ipython to install it like below.
    $ pip3 install ipython
    Collecting ipython
      Downloading https://files.pythonhosted.org/packages/14/3b/3fcf422a99a04ee493e6a4fc3014e3c8ff484a7feed238fef68bdc285085/ipython-7.3.0-py3-none-any.whl (768kB)
        100% |████████████████████████████████| 778kB 1.1MB/s 
    Collecting jedi>=0.10 (from ipython)
      Downloading https://files.pythonhosted.org/packages/25/2b/1f188901be099d52d7b06f4d3b7cb9f8f09692c50697b139eaf6fa2928d8/jedi-0.13.3-py2.py3-none-any.whl (178kB)
        100% |████████████████████████████████| 184kB 2.4MB/s 
    Collecting setuptools>=18.5 (from ipython)
      Downloading https://files.pythonhosted.org/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl (575kB)
        100% |████████████████████████████████| 583kB 1.8MB/s 
    Collecting backcall (from ipython)
      Downloading https://files.pythonhosted.org/packages/84/71/c8ca4f5bb1e08401b916c68003acf0a0655df935d74d93bf3f3364b310e0/backcall-0.1.0.tar.gz
    Collecting pexpect; sys_platform != "win32" (from ipython)
      Downloading https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl (57kB)
        100% |████████████████████████████████| 61kB 3.0MB/s 
    Collecting prompt-toolkit<2.1.0,>=2.0.0 (from ipython)
      Downloading https://files.pythonhosted.org/packages/f7/a7/9b1dd14ef45345f186ef69d175bdd2491c40ab1dfa4b2b3e4352df719ed7/prompt_toolkit-2.0.9-py3-none-any.whl (337kB)
        100% |████████████████████████████████| 337kB 2.1MB/s 
    Collecting traitlets>=4.2 (from ipython)
      Downloading https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl (74kB)
        100% |████████████████████████████████| 81kB 2.7MB/s 
    Collecting decorator (from ipython)
      Downloading https://files.pythonhosted.org/packages/f1/cd/7c8240007e9716b14679bc217a1baefa4432aa30394f7e2ec40a52b1a708/decorator-4.3.2-py2.py3-none-any.whl
    Collecting pygments (from ipython)
      Downloading https://files.pythonhosted.org/packages/13/e5/6d710c9cf96c31ac82657bcfb441df328b22df8564d58d0c4cd62612674c/Pygments-2.3.1-py2.py3-none-any.whl (849kB)
        100% |████████████████████████████████| 849kB 1.4MB/s 
    Collecting pickleshare (from ipython)
      Downloading https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
    Collecting parso>=0.3.0 (from jedi>=0.10->ipython)
      Downloading https://files.pythonhosted.org/packages/19/b1/522b2671cc6d134c9d3f5dfc0d02fee07cab848e908d03d2bffea78cca8f/parso-0.3.4-py2.py3-none-any.whl (93kB)
        100% |████████████████████████████████| 102kB 2.6MB/s 
    Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
      Downloading https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
    Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->ipython)
      Downloading https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
    Collecting six>=1.9.0 (from prompt-toolkit<2.1.0,>=2.0.0->ipython)
      Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
    Collecting ipython-genutils (from traitlets>=4.2->ipython)
      Downloading https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
    Building wheels for collected packages: backcall
      Running setup.py bdist_wheel for backcall ... done
      Stored in directory: /home/zhaosong/.cache/pip/wheels/98/b0/dd/29e28ff615af3dda4c67cab719dd51357597eabff926976b45
    Successfully built backcall
    Installing collected packages: parso, jedi, setuptools, backcall, ptyprocess, pexpect, wcwidth, six, prompt-toolkit, ipython-genutils, decorator, traitlets, pygments, pickleshare, ipython
    Successfully installed backcall-0.1.0 decorator-4.3.2 ipython-7.3.0 ipython-genutils-0.2.0 jedi-0.13.3 parso-0.3.4 pexpect-4.6.0 pickleshare-0.7.5 prompt-toolkit-2.0.9 ptyprocess-0.6.0 pygments-2.3.1 setuptools-40.8.0 six-1.12.0 traitlets-4.3.2 wcwidth-0.1.7
    (base) zhaosong@zhaosong-VirtualBox:~$ pip3 show ipython
    Name: ipython
    Version: 7.3.0
    Summary: IPython: Productive Interactive Computing
    Home-page: https://ipython.org
    Author: The IPython Development Team
    Author-email: [email protected]
    License: BSD
    Location: /home/zhaosong/.local/lib/python3.6/site-packages
    Requires: decorator, pickleshare, setuptools, traitlets, jedi, pygments, pexpect, backcall, prompt-toolkit
    

2. Run Python Code In IPython.

  1. Open a terminal and input $ ipython command. Then you can write python source code in the iPython console.
    (base) zhaosong@zhaosong-VirtualBox:~$ ipython
    Python 3.7.1 (default, Dec 14 2018, 19:28:38) 
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: print('hello world')                                                                                                                                                                                
    hello world
    
    In [2]: a = 5                                                                                                                                                                                               
    
    In [3]: b = 6                                                                                                                                                                                               
    
    In [4]: a + b                                                                                                                                                                                               
    Out[4]: 11
    
    In [5]: def sum(a, b): 
       ...:     return a + b 
       ...:                                                                                                                                                                                                     
    
    In [6]: sum(1,2)                                                                                                                                                                                            
    Out[6]: 3
    
    In [7]:

3. Install Jupyter NoteBook.

Jupyter notebook is a browser-server-based website tool that can help you to write and run Python source code interactively. When you run it, it will start a web server, and then you can create a working folder and notebook file ( which file extension is .ipynb ) in it. In each notebook file, you can write text in line cell input text box and mark the text as Code ( python source code ), Markdown ( comments), Raw NBConvert, or Heading type.

Then you can submit the text to the Jupyter webserver to execute. If you submit Python source code, the Jupyter web server will create an iPython process to run it, and the execution result will be displayed below the python source code on the web page immediately.

But before use it, you should install it first, you have two ways to install it.

  1. Install Anaconda: Anaconda integrates with Jupyter by default, so after installing anaconda, you can use Jupyter directly. You can refer to How To Install Anaconda On Linux, Windows, macOS Correctly.
  2. Use pip to install Jupyter: Open a terminal and run $ pip3 show jupyter to check whether Jupyter has been installed or not. Below output means Jupyter has been installed.
    ~$ pip3 show jupyter
    Name: jupyter
    Version: 1.0.0
    Summary: Jupyter metapackage. Install all the Jupyter components in one go.
    Home-page: http://jupyter.org
    Author: Jupyter Development Team
    Author-email: [email protected]
    License: BSD
    Location: /home/zhaosong/.local/lib/python3.6/site-packages
    Requires: ipykernel, qtconsole, ipywidgets, notebook, nbconvert, jupyter-console
    
  3. If Jupyter is not installed, run $ pip3 install jupyter to install it. It will download and install a lot of dependency packages like below.
    $ pip3 install jupyter
    Collecting jupyter
      Downloading https://files.pythonhosted.org/packages/83/df/0f5dd132200728a86190397e1ea87cd76244e42d39ec5e88efd25b2abd7e/jupyter-1.0.0-py2.py3-none-any.whl
    Collecting jupyter-console (from jupyter)
      Downloading https://files.pythonhosted.org/packages/cb/ee/6374ae8c21b7d0847f9c3722dcdfac986b8e54fa9ad9ea66e1eb6320d2b8/jupyter_console-6.0.0-py2.py3-none-any.whl
    Collecting qtconsole (from jupyter)
      Downloading https://files.pythonhosted.org/packages/e0/7a/8aefbc0ed078dec7951ac9a06dcd1869243ecd7bcbce26fa47bf5e469a8f/qtconsole-4.4.3-py2.py3-none-any.whl (113kB)
        100% |████████████████████████████████| 122kB 215kB/s 
    Collecting ipywidgets (from jupyter)
      Downloading https://files.pythonhosted.org/packages/30/9a/a008c7b1183fac9e52066d80a379b3c64eab535bd9d86cdc29a0b766fd82/ipywidgets-7.4.2-py2.py3-none-any.whl (111kB)
        100% |████████████████████████████████| 112kB 640kB/s 
    Collecting notebook (from jupyter)
      Downloading https://files.pythonhosted.org/packages/f8/a6/dbdf0954d073ab2cf5421cad20334d1e4c780da37205c04522c045298f67/notebook-5.7.4-py2.py3-none-any.whl (9.0MB)
        100% |████████████████████████████████| 9.0MB 189kB/s 
    Collecting nbconvert (from jupyter)
      Downloading https://files.pythonhosted.org/packages/b8/39/1e67fea74dc9577cc49f9863fe3ec824e525d1304ab6027d95a94cd586f5/nbconvert-5.4.1-py2.py3-none-any.whl (407kB)
        100% |████████████████████████████████| 409kB 1.9MB/s 
    Collecting ipykernel (from jupyter)
      Downloading https://files.pythonhosted.org/packages/d8/b0/f0be5c5ab335196f5cce96e5b889a4fcf5bfe462eb0acc05cd7e2caf65eb/ipykernel-5.1.0-py3-none-any.whl (113kB)
        100% |████████████████████████████████| 122kB 4.2MB/s 
    Collecting jupyter-client (from jupyter-console->jupyter)
      Downloading https://files.pythonhosted.org/packages/3b/c3/3043fe9ffd140d03c9d091a056794ccdc427c56ec19b8eea74f9ea0a498f/jupyter_client-5.2.4-py2.py3-none-any.whl (89kB)
        100% |████████████████████████████████| 92kB 4.8MB/s 
    Collecting pygments (from jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/13/e5/6d710c9cf96c31ac82657bcfb441df328b22df8564d58d0c4cd62612674c/Pygments-2.3.1-py2.py3-none-any.whl
    Collecting prompt-toolkit<2.1.0,>=2.0.0 (from jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/f7/a7/9b1dd14ef45345f186ef69d175bdd2491c40ab1dfa4b2b3e4352df719ed7/prompt_toolkit-2.0.9-py3-none-any.whl
    Collecting ipython (from jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/14/3b/3fcf422a99a04ee493e6a4fc3014e3c8ff484a7feed238fef68bdc285085/ipython-7.3.0-py3-none-any.whl
    Collecting jupyter-core (from qtconsole->jupyter)
      Downloading https://files.pythonhosted.org/packages/1d/44/065d2d7bae7bebc06f1dd70d23c36da8c50c0f08b4236716743d706762a8/jupyter_core-4.4.0-py2.py3-none-any.whl (126kB)
        100% |████████████████████████████████| 133kB 5.0MB/s 
    Collecting traitlets (from qtconsole->jupyter)
      Using cached https://files.pythonhosted.org/packages/93/d6/abcb22de61d78e2fc3959c964628a5771e47e7cc60d53e9342e21ed6cc9a/traitlets-4.3.2-py2.py3-none-any.whl
    Collecting ipython-genutils (from qtconsole->jupyter)
      Using cached https://files.pythonhosted.org/packages/fa/bc/9bd3b5c2b4774d5f33b2d544f1460be9df7df2fe42f352135381c347c69a/ipython_genutils-0.2.0-py2.py3-none-any.whl
    Collecting nbformat>=4.2.0 (from ipywidgets->jupyter)
      Downloading https://files.pythonhosted.org/packages/da/27/9a654d2b6cc1eaa517d1c5a4405166c7f6d72f04f6e7eea41855fe808a46/nbformat-4.4.0-py2.py3-none-any.whl (155kB)
        100% |████████████████████████████████| 163kB 1.7MB/s 
    Collecting widgetsnbextension~=3.4.0 (from ipywidgets->jupyter)
      Downloading https://files.pythonhosted.org/packages/8a/81/35789a3952afb48238289171728072d26d6e76649ddc8b3588657a2d78c1/widgetsnbextension-3.4.2-py2.py3-none-any.whl (2.2MB)
        100% |████████████████████████████████| 2.2MB 563kB/s 
    Collecting terminado>=0.8.1 (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/2e/20/a26211a24425923d46e1213b376a6ee60dc30bcdf1b0c345e2c3769deb1c/terminado-0.8.1-py2.py3-none-any.whl
    Collecting tornado>=4 (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/b1/7f/8109821ff9df1bf3519169e34646705c32ac13be6a4d51a79ed57f47686e/tornado-6.0.1.tar.gz (481kB)
        100% |████████████████████████████████| 491kB 1.4MB/s 
    Collecting jinja2 (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
        100% |████████████████████████████████| 133kB 2.0MB/s 
    Collecting Send2Trash (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/49/46/c3dc27481d1cc57b9385aff41c474ceb7714f7935b1247194adae45db714/Send2Trash-1.5.0-py3-none-any.whl
    Collecting prometheus-client (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/4c/bd/b42db3ec90ffc6be805aad09c1cea4bb13a620d0cd4b21aaa44d13541d71/prometheus_client-0.6.0.tar.gz
    Collecting pyzmq>=17 (from notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/5f/04/f6f0fa20b698b29c6e6b1d6b4b575c12607b0abf61810aab1df4099988c6/pyzmq-18.0.1-cp36-cp36m-manylinux1_x86_64.whl (1.1MB)
        100% |████████████████████████████████| 1.1MB 1.1MB/s 
    Collecting pandocfilters>=1.4.1 (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/4c/ea/236e2584af67bb6df960832731a6e5325fd4441de001767da328c33368ce/pandocfilters-1.4.2.tar.gz
    Collecting testpath (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/be/a4/162f9ebb6489421fe46dcca2ae420369edfee4b563c668d93cb4605d12ba/testpath-0.4.2-py2.py3-none-any.whl (163kB)
        100% |████████████████████████████████| 163kB 3.2MB/s 
    Collecting bleach (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/ab/05/27e1466475e816d3001efb6e0a85a819be17411420494a1e602c36f8299d/bleach-3.1.0-py2.py3-none-any.whl (157kB)
        100% |████████████████████████████████| 163kB 4.2MB/s 
    Collecting defusedxml (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/87/1c/17f3e3935a913dfe2a5ca85fa5ccbef366bfd82eb318b1f75dadbf0affca/defusedxml-0.5.0-py2.py3-none-any.whl
    Collecting mistune>=0.8.1 (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/09/ec/4b43dae793655b7d8a25f76119624350b4d65eb663459eb9603d7f1f0345/mistune-0.8.4-py2.py3-none-any.whl
    Collecting entrypoints>=0.2.2 (from nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/ac/c6/44694103f8c221443ee6b0041f69e2740d89a25641e62fb4f2ee568f2f9c/entrypoints-0.3-py2.py3-none-any.whl
    Collecting python-dateutil>=2.1 (from jupyter-client->jupyter-console->jupyter)
      Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
        100% |████████████████████████████████| 235kB 2.6MB/s 
    Collecting wcwidth (from prompt-toolkit<2.1.0,>=2.0.0->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/7e/9f/526a6947247599b084ee5232e4f9190a38f398d7300d866af3ab571a5bfe/wcwidth-0.1.7-py2.py3-none-any.whl
    Collecting six>=1.9.0 (from prompt-toolkit<2.1.0,>=2.0.0->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
    Collecting pexpect; sys_platform != "win32" (from ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/89/e6/b5a1de8b0cc4e07ca1b305a4fcc3f9806025c1b651ea302646341222f88b/pexpect-4.6.0-py2.py3-none-any.whl
    Collecting setuptools>=18.5 (from ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-40.8.0-py2.py3-none-any.whl
    Collecting pickleshare (from ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/9a/41/220f49aaea88bc6fa6cba8d05ecf24676326156c23b991e80b3f2fc24c77/pickleshare-0.7.5-py2.py3-none-any.whl
    Collecting jedi>=0.10 (from ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/25/2b/1f188901be099d52d7b06f4d3b7cb9f8f09692c50697b139eaf6fa2928d8/jedi-0.13.3-py2.py3-none-any.whl
    Collecting decorator (from ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/f1/cd/7c8240007e9716b14679bc217a1baefa4432aa30394f7e2ec40a52b1a708/decorator-4.3.2-py2.py3-none-any.whl
    Collecting backcall (from ipython->jupyter-console->jupyter)
    Collecting jsonschema!=2.5.0,>=2.4 (from nbformat>=4.2.0->ipywidgets->jupyter)
      Downloading https://files.pythonhosted.org/packages/aa/69/df679dfbdd051568b53c38ec8152a3ab6bc533434fc7ed11ab034bf5e82f/jsonschema-3.0.1-py2.py3-none-any.whl (54kB)
        100% |████████████████████████████████| 61kB 10.0MB/s 
    Collecting ptyprocess; os_name != "nt" (from terminado>=0.8.1->notebook->jupyter)
      Using cached https://files.pythonhosted.org/packages/d1/29/605c2cc68a9992d18dada28206eeada56ea4bd07a239669da41674648b6f/ptyprocess-0.6.0-py2.py3-none-any.whl
    Collecting MarkupSafe>=0.23 (from jinja2->notebook->jupyter)
      Downloading https://files.pythonhosted.org/packages/b2/5f/23e0023be6bb885d00ffbefad2942bc51a620328ee910f64abe5a8d18dd1/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl
    Collecting webencodings (from bleach->nbconvert->jupyter)
      Downloading https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
    Collecting parso>=0.3.0 (from jedi>=0.10->ipython->jupyter-console->jupyter)
      Using cached https://files.pythonhosted.org/packages/19/b1/522b2671cc6d134c9d3f5dfc0d02fee07cab848e908d03d2bffea78cca8f/parso-0.3.4-py2.py3-none-any.whl
    Collecting pyrsistent>=0.14.0 (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter)
      Downloading https://files.pythonhosted.org/packages/8c/46/4e93ab8a379d7efe93f20a0fb8a27bdfe88942cc954ab0210c3164e783e0/pyrsistent-0.14.11.tar.gz (104kB)
        100% |████████████████████████████████| 112kB 4.3MB/s 
    Collecting attrs>=17.4.0 (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->jupyter)
      Downloading https://files.pythonhosted.org/packages/23/96/d828354fa2dbdf216eaa7b7de0db692f12c234f7ef888cc14980ef40d1d2/attrs-19.1.0-py2.py3-none-any.whl
    Building wheels for collected packages: tornado, prometheus-client, pandocfilters, pyrsistent
      Running setup.py bdist_wheel for tornado ... done
      Stored in directory: /home/zhaosong/.cache/pip/wheels/09/a9/78/41e23ffcb122e8f4b02537f4480a276ec1ad760dd492373961
      Running setup.py bdist_wheel for prometheus-client ... done
      Stored in directory: /home/zhaosong/.cache/pip/wheels/4b/04/b8/3709c73e7453f311ebd46ad581b89642543213f995e2659b9e
      Running setup.py bdist_wheel for pandocfilters ... done
      Stored in directory: /home/zhaosong/.cache/pip/wheels/39/01/56/f1b08a6275acc59e846fa4c1e1b65dbc1919f20157d9e66c20
      Running setup.py bdist_wheel for pyrsistent ... done
      Stored in directory: /home/zhaosong/.cache/pip/wheels/83/59/9a/a037b9b3c3e93d9275ea0aff9d6064400f372879dfdab01afe
    Successfully built tornado prometheus-client pandocfilters pyrsistent
    Installing collected packages: six, python-dateutil, ipython-genutils, decorator, traitlets, jupyter-core, pyzmq, tornado, jupyter-client, pygments, wcwidth, prompt-toolkit, ptyprocess, pexpect, setuptools, pickleshare, parso, jedi, backcall, ipython, ipykernel, jupyter-console, qtconsole, pyrsistent, attrs, jsonschema, nbformat, terminado, MarkupSafe, jinja2, Send2Trash, pandocfilters, testpath, webencodings, bleach, defusedxml, mistune, entrypoints, nbconvert, prometheus-client, notebook, widgetsnbextension, ipywidgets, jupyter
    Successfully installed MarkupSafe-1.1.1 Send2Trash-1.5.0 attrs-19.1.0 backcall-0.1.0 bleach-3.1.0 decorator-4.3.2 defusedxml-0.5.0 entrypoints-0.3 ipykernel-5.1.0 ipython-7.3.0 ipython-genutils-0.2.0 ipywidgets-7.4.2 jedi-0.13.3 jinja2-2.10 jsonschema-3.0.1 jupyter-1.0.0 jupyter-client-5.2.4 jupyter-console-6.0.0 jupyter-core-4.4.0 mistune-0.8.4 nbconvert-5.4.1 nbformat-4.4.0 notebook-5.7.4 pandocfilters-1.4.2 parso-0.3.4 pexpect-4.6.0 pickleshare-0.7.5 prometheus-client-0.6.0 prompt-toolkit-2.0.9 ptyprocess-0.6.0 pygments-2.3.1 pyrsistent-0.14.11 python-dateutil-2.8.0 pyzmq-18.0.1 qtconsole-4.4.3 setuptools-40.8.0 six-1.12.0 terminado-0.8.1 testpath-0.4.2 tornado-6.0.1 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.4.2
    

4. Run Jupyter Notebook Web Server.

  1. After Jupyter has been installed successfully, you can run the command $ jupyter notebook in terminal to start the Jupyter web server.
    ~$ jupyter notebook
    [I 22:21:57.057 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
    [I 22:21:57.234 NotebookApp] JupyterLab extension loaded from /home/zhaosong/anaconda3/lib/python3.7/site-packages/jupyterlab
    [I 22:21:57.234 NotebookApp] JupyterLab application directory is /home/zhaosong/anaconda3/share/jupyter/lab
    [I 22:21:57.235 NotebookApp] Serving notebooks from local directory: /home/zhaosong
    [I 22:21:57.235 NotebookApp] The Jupyter Notebook is running at:
    [I 22:21:57.236 NotebookApp] http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266
    [I 22:21:57.236 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 22:21:57.254 NotebookApp] 
        
        To access the notebook, open this file in a browser:
            file:///run/user/1000/jupyter/nbserver-13959-open.html
        Or copy and paste one of these URLs:
            http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266
    
  2. Copy and browse the above HTTP url http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266 to go to the Jupyter website home page. Please do not lose the token generated in the url, if you do not provide the token, you will enter the below error page that requires you to input the token value.

    Password or token:          Log in
    Token authentication is enabled
    If no password has been configured, you need to open the notebook server with its login token in
    the URL. or paste it above. This requirement will be lifted if you enable a password.
    
    The command:
           jupyter notebook list
    
    will show you the URLs of running severs with their tokens. which you can copy and paste into
    
    your browser. For example:
    
            Currently running servers:
            http://localhost:BB88/?token-cBde56fa. .. :: /Users/you/notebooks
    or you can paste just the token value into the password field on this page.
    See the documentation on how to enable a password in place of token authentication. if you
    would like to avoid dealing with random tokens.
  3. If you browse url http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266 with the correct token value, then you will be directed to the Jupyter home page.

5. Execute Python Code In Jupyter Interactively.

  1. On the Jupyter notebook web server home page, click the New drop-down menu list on the top right corner, and you can select Python 3 menu item to create an executable python 3 notebook file. Click the Folder menu item to create a working folder.
  2. Click the file name Untitled.ipynb, you will go to the notebook editor page like below. Click Untitled in the top left corner, you can change the Jupyter notebook file name.
    jupyter-ipynb-file-editor-page
  3. Then you can input text in the line cell input text box. You can also specify the line cell text value type from the drop-down list at the end of the toolbar icons. There are four text value types: Code ( python source code ), Markdown ( comments ), Raw NBConvert, Heading.
  4. If you select Code type for the line cell text, then click the Run button will submit the line cell text value to the Jupyter server to run. Then Jupyter will start an iPython kernel to run the python source code on the server-side.
  5. You can input all kinds of python source code, such as to define python function, import libraries even run matpolib code to generate the chart, then the chart image will be displayed on the web page also.

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.