Every day the number of Python notebooks grows. Developers around the world have fully embraced Jupyter Notebook and now it’s become a must-have in the industry.
I first noticed this trend in 2019, but back then I didn’t feel inspired to change, but in 2020 more and more developers embraced Jupyter Notebooks. I saw Python developers praising Jupyter Notebook on YouTube and taking it for granted that everyone else was a convert too.
Jupyter Notebook Advantages
- Convenient for the initial development of code
- Helps segment your code (and re-run segments)
- Stores values of variables from segments you’ve already run
Ultimately, I made the leap to understand how Jupyter Notebook works. How great could it be? Now I’m one of those converted developers. It feels like I’ve always used Jupyter Notebook; like it’s always been there. It’s really come to feel like the simplest tool in the world. It won’t replace your regular Python environment but it will drastically enhance it.
What Is Jupyter Notebook?
Jupyter Notebook is a web-based application used to create and share interactive notebook documents, which can contain live code, text, data visualizations, videos and other computational outputs. Created by Project Jupyter, the application is open-source and supports the use of over 40 programming languages, including Python, R and Scala.
Jupyter Notebook showcases real-time code results and imagery, and can execute cells in any order. This makes it a useful tool for quick code experimentation, designing code presentations or facilitating data science workflows.
Why Use Jupyter Notebook?
1. Initial Code Development and Segmentation
Jupyter Notebook is convenient for the initial development of code. It allows you to segment your code (and re-run segments of your code) while storing the values of variables from segments you’ve already run. Here’s an example:
Here is the same notebook on GitHub.
As you can see in this example, each cell runs separately. This is great when a certain part of your code contains never-ending arrays or a machine learning training operation. With Jupyter you can run these long operations once, create a new cell below, and use the values you obtain from previous cells.
2. Creating Documentation and Tutorials
Another situation where developers often use Jupyter is to create documentation or tutorials for their team. You can explain your thought process much better in a notebook rather than using internal comments within your code.
How to Install and Use Jupyter Notebook
Jupyter Notebook can be installed using the Anaconda distribution or Miniconda (recommended for new Python users), or by using pip, Python’s default package manager (recommended for experienced Python users).
For this tutorial, we’ll use the pip installation method and focus on installation for Windows and macOS systems.
1. Download and Install Python
Download the latest version of Python for Windows or macOS from the Python official website, and install the program accordingly.
For Windows: In the Python Setup window, check the “Add Python to PATH” box before clicking install.
2. Open Terminal and Install Jupyter Notebook
Open Terminal on your computer and type the following text in the window:
pip install notebook
pip3 install notebook
Press enter to start the installation. You should see multiple lines of text running in the Terminal window, which means Jupyter Notebook is installing. The text will stop running once installation is complete.
3. Launch Jupyter Notebook Using Terminal
After installing Jupyter Notebook, type the following text in the Terminal window:
Press enter and this will automatically launch the Jupyter Notebook application in your default web browser.
4. Create New Notebook
In the opened Jupyter Notebook webpage, click the “New” button and select “Python 3” from the dropdown menu. This will open another webpage for a new notebook document.
As an extra visual, I took the liberty of creating a tutorial explaining how to install and use Jupyter Notebook ... in a Jupyter Notebook document.
You can access the notebook above from GitHub.
A Caveat: Jupyter Notebook Isn’t Always Your Best Tool
Despite how useful Jupyter is, it still doesn’t replace an integrated development environment (IDE) like PyCharm or Visual Studio Code. If you need to create long, self-contained classes or just pack your code for submission you might prefer moving your code from Jupyter to an IDE. Jupyter is great for development, but once you’ve done the developing, it isn’t the best place for constant implementation.
Another important difference to consider is code completion. By default, Jupyter Notebook offers weak code completion features when compared to an IDE like PyCharm, so you better know your code well.
Jupyter also offers JupyterLab alongside Jupyter Notebook. I have to warn you off using JupyterLab instead of Jupyter Notebook, though. I’ve tried both and I’ve found JupyterLab lacks certain key functionalities you find in Jupyter Notebook.
Don’t Take My Word on Jupyter Notebook
Many developers and researchers are involved with projects that require Python on a daily basis. Regardless of your coding skills, Jupyter Notebook adds value to a backend or (especially) analytics team. Jupyter provides a framework and interface that encourages good knowledge management practices by allowing for clear documentation and chronological explanation of the implemented code.
In the end, if you use Python regularly but don’t use Jupyter Notebook (yet), then you might want to reconsider your life choices. I did.
Frequently Asked Questions
What is Jupyter Notebook used for?
Jupyter Notebook is used to create interactive notebook documents that can contain live code, equations, visualizations, media and other computational outputs.
Jupyter Notebook is often used by programmers, data scientists and students to document and demonstrate coding workflows or simply experiment with code.
What is the difference between Python and Jupyter Notebook?
Python is a programming language used across various software engineering and software development areas.
Jupyter Notebook is a web application and computing environment that can be used for programming tasks. Jupyter Notebook's default kernel (ipykernel) is Python-based, which allows Python code to be executed within notebook documents by default.