Jupyter Notebook is a web application that allows you to create and share documents that contain:
- Live code (e.g. Python code)
- Explanatory Text (written in markdown syntax)
The Python Developer Survey by Jetbrains in 2018, showed that Jupyter Notebook is among the top 5 IDEs preferred by programmers, especially for Machine Learning and Data Analysis.
Jupyter Notebook’s ability to combine code, visualizations and rich text and the fact that you can share your notebook with the community, makes it suitable for performaing data anlysis in real time and adding a story telling aspect to your analysis.
This blog will help you in installing Jupyter Notebook for programming in Python. We’ll explore the basic functionality of Jupyter Notebook.
Let’s get started and install Jupyter Notebook on your computer.
- Setting-up Jupyter Notebook
- Managing Python version on the Jupyter Notebook
- Uninstalling old kernels
- Creating a new jupyter notebook
- Working with the Notebook
- Edit and Command Mode
- Exporting the Notebook
Setting-up Jupyter Notebook
The first step to get started is to visit the project’s website.
Here you’ll find two options:
- Try it in your browser
- Install the Notebook
In the first option, Try it in your browser you can access a hosted version of Jupyter Notebook. This will get you direct access without needing to install it on your computer.
The second option, Install the Notebook will take you to another page which gives you detailed instructions for the installation. There are two different ways:
- Installing Jupyter Notebook by using the Python’s package manager
- Installing Jupyter Notebook by installing the Anaconda distribution
Especially if you’re new to Python and would like to set up your development environment from scratch using the Anaconda distribution is a great choice. If you follow the link to the Anaconda download page you can choose between installers for Windows, macOS, and Linux.
Go for Installers with Python version more than 3. Python 2 is soon going to be deprecated. If you are unaware of the differences between Python 3 and 2, check out this article.
Managing Python version on the Jupyter Notebook
If you already have jupyter installed with a version lower than 3.7 you can create a new kernel with python version by executing the following commands on the conda prompt.
Once you are in the prompt, execute the following commands.
$ conda create -n Python_3.7 python=3.7 ipykernel
This command will create a new kernel with python version 3.7.
$ activate Python_3.7
This command will activate the new Kernel.
$ pip install ipykernel
Now we’ll install the ipykernel module for our new python version.
$ python -m ipykernel install –name Python_3.7
By using this command we are installing the new kernel into Jupyter.
Uninstalling old kernels
To uninstall the old kernel we’ll run these commands in the conda prompt.
$ jupyter kernelspec list
Here you will find all the kernel installed on the jupyter notebook. Find the name of the default kernel (Mostly it is Python 3).
To uninstall the kernel we’ll run this command:
$ jupyter kernelspec uninstall <unwanted-kernel>
Creating a new jupyter notebook
Having installed the Anaconda distribution, we can now start Jupyter Notebook by using the following command.
$ jupyter notebook
You’ll see the following response on the command line.
The web server is started, and the Jupyter Notebook application is opened in your default browser automatically. You should be able to see a browser output which is similar to the following screenshot.
As you can see the user interface of Jupyter Notebook is split up into three sections (tabs) -
The default view is the Files tab from where you can open or create notebooks.
Creating a new Jupyter Notebook is easy. Just use the New dropdown menu and you’ll see the following options as below.
Select option Python 3 to open a new Jupyter Notebook for Python. The notebook is created, and you should be able to see something similar to the below screenshot.
The notebook is created but still untitled. By clicking into the text Untitled on the top you can give it a name. By giving it a name, the notebook will also be saved as a file of the same name with extension
.ipynb. E.g. name the notebook
Switching back to the
Files tab you’ll be able to see a new file code1.ipynb.
Because this notebook file is opened right now, the file is marked with status Running. From here you can decide to shut down this notebook by clicking on the button Shutdown.
However, before shutting down the notebook let’s switch back to the notebook view and try out a few things to get familiar with the notebook concept.
Working with the Notebook
The notebook itself consists of cells. A first empty cell is already available after having created the new notebook.
This cell is of type
Code and you can start typing in Python code directly. Executing code in this cell can be done by either clicking on the run cell button or hitting
Shift + Enter keys.
The resulting output becomes visible right underneath the cell.
Edit and Command Mode
If a cell is active, two modes can be distinguished -
- edit mode
- command mode
If you just click in one cell the cell is opened in command mode which is indicated by a blue border on the left.
The edit mode is entered if you click into the code area of that cell. This mode is indicated by a green border on the left side of the cell.
If you’d like to leave edit mode and return to command mode again you just need to hit
To get an overview of functions which are available in command and in edit mode, you can open up the overview of key shortcuts by using menu entry
Help → Keyboard Shortcuts.
Exporting the Notebook
Jupyter Notebook gives you several options to export your notebook. Those options can be found in menu
File → Download as.
This was a generic overview on Getting Started with the Jupyter Notebooks. If you are interested to learn more about Jupyter Notebooks, make sure to put them down in the comments section below. We will come back with a blog or video on the topic.