4x Affordable, 99.95% SLA, 24x& Video Support, 100+ Countires

Set Up Jupyter Notebook For Python 3


Jupyter Notebook offers a control shell for interactive reasoning as a web application. The equipment can be used with several communications, including Python, Julia, R, Haskell, and Ruby. It is often used for working with data, statistical version, and device learning.

This tutorial will walk you through setting up Jupyter Notebook to run either locally or from an ubuntu 16.04 server, as well as inform you how to connect to and use the notebook. Jupyter notebooks (or simply notebooks) are paper-work produced by the Jupyter Notebook app which include both computer code and rich matter components (paragraph, equations, figures, links, etc.) which help in showing and overlapping reproducible research.

By the end of this lead, you will be able to run Python 3 code using Jupyter Notebook running on a local device or far server.


To follow this tutorial, you will need a python 3 app environment, either

All the controls in this tutorial should be run as a non-set user. If set accesses is demanded for the regulate, it will be preceded by sudo. first Server Setup with Ubuntu 16.04 explains how to increase users and give them sudo accesses.

Step 1 Installing Jupyter Notebook

In this portion we will install Jupyter Notebook with pip.

Activate the Python 3 software environment you would like to install Jupyter Notebook into. In our instance, well install it into my_env, so we will ensure were in that environments directory and activate it like so:

  • cd ~/environments
  • . my_env/bin/activate

Next, we can ensure that pip is improved to the most new model:

  • pip install --upgrade pip

Now we can install Jupyter Notebook with the following control:

  • pip install jupyter

At this point Jupyter Notebook is installed into the actual app environment.

The next elective stride is for those connecting a server installation of the web interface using SSH tunnelling.

Step 2 (Optional) Using SSH Tunneling to Connect to a Server Installation

If you installed Jupyter Notebook on a server, in this part we will learn how to connect to the Jupyter Notebook web interface using SSH tunneling. Since Jupyter Notebook will run on a precise port on the server (such as :8888, :8889 etc.), SSH tunneling enables you to connect to the servers port securely.

The next two subsections describe how to create a ssh tunnel from 1) a mac or linux and 2) windows. Please refer to the subsection for your local computer.

SSH Tunneling with a Mac or Linux

If you are using a mac or linux, the stages for creating a ssh tunnel are akin to the How To Use SSH Keys with F(x) data cloud machines using linux or Mac lead except there are extra parameters increased in the ssh regulate. This subsection will outline the more parameters needed in the ssh regulate to tunnel successfully.

SSH tunneling can be done by running the following SSH control in a brand-new local terminal window:

  • ssh -L 8888:localhost:8888 your_server_username@your_server_ip

The ssh regulate opens a ssh connection, but -L specifies that the given port on the local (case) host is to be forwarded to the given host and port on the far side (server). This means that whatever is running on the ordinal port number (e.g. 8888) on the server will be on the first port number (e.g. 8888) on your local computer.

Optionally action port 8888 to one of your selecting to elude using a port already in use by another processes.

server_username is your username (e.g. sammy) on the server which you created and your_server_ip is the IP addresses of your server.

For instance, for the username sammy and the server addresses, the regulate would be:

  • ssh -L 8888:localhost:8888 sammy@

If no error shows up after running the ssh -L control, you can move into your app environment and run Jupyter Notebook:

  • jupyter notebook

Youll receive output with a URL. From a web browser on your local device, open the Jupyter Notebook web interface with the URL that starts with http://localhost:8888. Ensure that the minimal number is included, or enter the minimal number string when prompted at http://localhost:8888.

SSH Tunneling with Windows and Putty

If you are using windows, you can create a ssh tunnel using cement as outlined in How To Use SSH Keys with cement on F(x) data cloud machines (windows users).

First, enter the server url or IP addresses as the hostname as shown :

Set Hostname for SSH Tunnel

Next, depression SSH on the bottom of the left pane to diversify the menu, and then depression Tunnels. Enter the local port number to use to access Jupyter on your local device. Choose 8000 or large to elude ports used by other services, and set the destination as localhost:8888 where :8888 is the number of the port that Jupyter Notebook is running on.

Now depression the increase badge, and the ports should be in the Forwarded ports database:

Forwarded ports list

Finally, depression the ajar badge to connect to the server via SSH and tunnel the desired ports. Navigate to http://localhost:8000 (or whatever port you chose) in a web browser to connect to Jupyter Notebook running on the server. Ensure that the minimal number is included, or enter the minimal number string when prompted at http://localhost:8000.

Step 3 Running Jupyter Notebook

With Jupyter Notebook installed, you can run it in your terminal. To do so, kill the following control:

  • jupyter notebook

a log of the activities of the Jupyter Notebook will be printed to the terminal. When you run Jupyter Notebook, it runs on a precise port number. The first notebook you are running will usually run on port 8888. To check the exact port number Jupyter Notebook is running on, refer to the production of the control used to begin it:

[I NotebookApp] Serving notebooks from local directory: /home/sammy [I NotebookApp] 0 active kernels [I NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/ [I NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). ...

If you are running Jupyter Notebook on a local computer (not on a server), your failure browser should have opened the Jupyter Notebook web app. If not, or if you close the window, you can navigate to the url given in the production, or navigate to localhost:8888 to connect.

Whenever you would like to stop the Jupyter Notebook processes, press CTRL+C, symbol Y when prompted, and then knocked ENTER to confirm.

Youll collect the following production:

[C 12:32:23.792 NotebookApp] Shutdown confirmed [I 12:32:23.794 NotebookApp] Shutting down kernels

Jupyter Notebook is now no longer running.

Step 4 Using Jupyter Notebook

This portion goes over the fact Synonyms/Hypernyms of using Jupyter Notebook. If you dont currently have Jupyter Notebook running, commence it with the jupyter notebook regulate.

You should now be connected to it using a web browser. Jupyter Notebook is very strong and has many features. This portion will outline a few of the basic features to get you began using the notebook. Jupyter Notebook will show all of the records and coverings in the directory it is run from, so when youre working on a project make convinced to begin it from the project directory.

To create a brand-new notebook register, specify brand-new > Python 3 from the top right pull-down menu:

Create a new Python 3 notebook

This will ajar a notebook. We can now run Python code in the compartment or action the compartment to markdown. For instance, action the first compartment to accept Markdown by moving compartment > compartment Type > Markdown from the top navigation bar. We can now write notes using Markdown and even include equations written in LaTeX by putting them between the $$ symbols. For example, symbol the following into the cell after changing it to markdown:

# Simple Equation

Let us now implement the following equation:
$$ y = x^2$$

where $x = 2$

To turn the markdown into rich matter, press CTRL+ENTER, and the following should be the results:

results of markdown

You can use the markdown compartments to make notes and paper-work your code. Let's implement that easy equation and print the result. depression on the top compartment, then press ALT+ENTER to increase a compartment below it. Enter the following code in the brand-new compartment.

x = 2
y = x**2

To run the code, press CTRL+ENTER. Youll collect the following results:

simple equation results

You now have the ability to import modules and use the notebook as you would with any other Python development environment!


Congratulations! You should now be able to write reproducible Python code and notes in Markdown using Jupyter Notebook. To get a fast tour of Jupyter Notebook from within the interface, specify support > User interface Tour from the top navigation menu to learn more.

From here, you may be curious to read our successions on moment successions Visualization and Forecasting.

Reference: digitalocean