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 provide more features that make your development process easy. Jupyter notebook is a browser-server based website tool which can save your python souce code in a .ipynb notebook file, and then when you submit the python source code to your local jupyter webserver, 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 develope interactive python souce code with examples.

1. Install IPython.

Before install IPython, you can run $ pip3 show ipython command to check whether it has been installed or not. This command will show it’s version and installation directory.

(base) :~$ pip3 show ipythonName: ipythonVersion: 7.3.0Summary: IPython: Productive Interactive ComputingHome-page: https://ipython.orgAuthor: The IPython Development TeamAuthor-email: READ :   How To Send Email With Gmail As Provider Using Python

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

  1. Install Anaconda : Anaconda integrate with Jupyter by default, so after install anaconda, you can use Jupyter directly. You can refer 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 jupyterName: jupyterVersion: 1.0.0Summary: Jupyter metapackage. Install all the Jupyter components in one go.Home-page: http://jupyter.orgAuthor: Jupyter Development TeamAuthor-email: READ :   How To Pass Parameters To View Via Url In Django

How To Use IPython Jupyter Notebook To Develop Python Code

If you browse url http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266 with correct token value, then you will get below jupyter home page.

How To Use IPython Jupyter Notebook To Develop Python Code

5. Execute Python Code In Jupyter Interactively.

  1. Click the New drop down menu list, and you can select Python 3 menu item to create a executable python 3 notebook file. Click Folder to create a working folder.
    How To Use IPython Jupyter Notebook To Develop Python Code
  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 file name.
    How To Use IPython Jupyter Notebook To Develop Python Code
  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 tool bar 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 Run button will submit the line cell text value to jupyter server to run. Then jupyter will start a ipython kernel to run the python source code at server side.
  5. You can input all kind of python source code, such as define python function, import libraries even run matpolib code to generate chart, then the chart image will be displayed in the web page also.
  • 203