How to Install Jupyter Notebook on Ubuntu

How to Install Jupyter Notebook on Ubuntu
Jupyter Notebook is one of the most widely used tool to execute Python interactively directly from a browser. With Jupyter Notebooks, we have an excellent opportunity to mix code with interactive exercises and documentation which doesn’t restrict us to keep our comments with # symbol and also allows to see the output of small snippet of our code directly in our browser. With the IPython 4.0 release, the language-independent parts of the project: the notebook style, message protocol, qtconsole, notebook web application, etc. have moved to a new project under the name Jupyter.

In this lesson, we will setup the Jupyter Notebook server on a Ubuntu machine and also connect to the Jupyter server as well with which we will be able to make new Jupyter Notebooks and run some sample Python code as well.

Getting Started

We will start by installing most basic components for this lesson which are Python and PIP. Let’s start with basic updates in our machine:

sudo apt-get update

Here is what we get back with this command:

Update machine

Next, we can install required components in a single command:

sudo apt-get -y install python2.7 python-pip python-dev

This installation might take some time to install depending on network speed as many dependencies are being installed here. We are using Python 2.7 with PIP package manager with which we can use and install many other python modules as we go. Finally, many of Jupyter’s dependencies work on Python-C extension, so we installed the python-dev dependency as well. To verify that everything went well, let us check the Python & PIP version with these commands:

python –version
pip –version

We will get back:

Python & PIP Version

Installing IPython & Juptyr

We can move on to installing most important parts of this lesson. Let us run the following commands to install IPython & Juptyr on our machine:

sudo apt-get -y install ipython
sudo -H pip install jupyter

Again, even this command can take more time to complete depending on network speed. Once this command is complete running, we can finally start the jupyter notebook as:

jupyter notebook –allow-root

You can start Jupyter as a non-root user as well. If you start Jupyter as a root user, we will have to use the –allow-root flag. Once this starts, the terminal will look like this:

Start Jupyter

Accessing Jupyter Console

We can access the Jupyter server from the URL shown in the console. If you’re running this server on a remote server, we will have to tunnel into the IP through SSH. We can do this with this command:

ssh -L 8000:localhost:8888 your_server_username@your_server_ip

Once you execute this command, you can again SSH into your server and execute the command to start Jupyter notebook with this command:

jupyter notebook –allow-root

Accessing Jupyter Notebook

Once you’ve started the Jupyter notebook server through SSH, you will see a URL like this in the terminal window:

http://localhost:8888/?token=8acc13e5fa48059e8ba0512bb54c616ed8ea100d5e25f639&token=8acc13e5fa48059e8ba0512bb54c616ed8ea100d5e25f639

Take note of one of the tokens in the URL. Now, open the following URL in your local machine browser:

http://localhost:8000/

You will see something like:

Accessing Jupyter

Once you’re in this screen, we can input the token we collected in previous step in the provided field. We will be inside once we hit Enter. We will see a screen like this:

Jupyter Notebook

We can now create a new notebook:

Creating new notebook

We can provide a name to this notebook by clicking on title bar:

Naming a Notebook

Finally, you can write sample Python code and execute in the browser itself:

Execute Python notebook

Conclusion

In this lesson, we looked at how we can install and start using Jupyter notebook server on Ubuntu 18.04 machine.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *