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.
But before use it, you should install it first, you have two way to install it.
- 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.
- Use pip to install Jupyter : Open a terminal and run
$ pip3 show jupyterto check whether jupyter has been installed or not. Below output means jupyter has been installed.
If you browse url http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266 with correct token value, then you will get below jupyter home page.
5. Execute Python Code In Jupyter Interactively.
- 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.
- 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.
- 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.
- 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.
- 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.