One place for hosting & domains

      Tunneling

      Einrichten von Jupyter Notebook mit Python 3 unter Ubuntu 20.04 und Connect über SSH Tunneling


      Einführung

      Jupyter Notebook ist eine Open-Source Webanwendung, um internaktiven Code, Visualisierungen und mehr zu erstellen und zu teilen. Dieses Tool kann mit verschiedenen Programmiersprachen genutzt werden, einschließlich Python, Julia, R, Haskell und Ruby. Er wird oft für das Arbeiten mit Daten, statistisches Modeling und Machine Learning genutzt.

      Jupyter Notebooks (oder kurz: „Notebooks“) werden durch die Jupyter App produziert, die sowohl Computercode als auch erweiterte Textelemente (Absätze, Gleichungen, Zahlen, Links, etc.) enthalten, die die Darstellung und Freigabe reproduzierbarer Ergebnisse unterstützen. Sie sind somit ein ausgezeichnetes Tool für datenbasierte oder programmbasierte Präsentationen oder als Lernwerkzeug.

      In diesem Tutorial befassen wir uns mit der Einrichtung von Jupyter Notebook auf einem Ubuntu 20.04-Server und zeigen, wie das Notebook via Tunnelling von einer lokalen Maschine verbunden und genutzt wird. Am Ende dieses Leitfadens können Sie Python 3 Code mit Jupyter Notebook auf einem Remote-Server ausführen.

      Voraussetzungen

      Um diesen Leitfaden erfolgreich zu absolvieren, sollten Sie eine neue Ubuntu 20.04-Serverinstanz mit einer einfachen Firewall und einem Nicht-root-Benutzer mit sudo-Berechtigungen konfiguriert haben. In unserem Leitfaden zur Ersteinrichtung des Servers erfahren Sie, wie Sie die Einrichtung vornehmen.

      Schritt 1 — Einrichten von Python

      Wir beginnen damit, die Abhängigkeiten zu installieren, die wir für unsere Python-Programmierung aus den Ubuntu Repositorys benötigen. Ubuntu 20.04 hat Python 3 vorinstalliert. Wir nutzen den Python Paketmanager pip, um später zusätzliche Komponenten zu installieren.

      Wir müssen zuerst den lokalen Paketindex apt aktualisieren und die Pakete herunterladen und installieren:

      Installieren Sie als Nächstes pip und die Python Header-Dateien, die von einigen der Jupyter-Abhängigkeiten genutzt werden:

      • sudo apt install python3-pip python3-dev

      Wir können nun mit der Einrichtung einer virtuellen Python-Umgebung fortfahren, in die wir Jupyter installieren.

      Schritt 2 — Erstellen einer virtuellen Python-Umgebung für Jupyter

      Nachdem wir nun Python 3 und seine Header-Dateien haben und pip bereit ist, können wir eine virtuelle Python-Umgebung erstellen, um unsere Projekte zu verwalten. Wir wollen Jupyter in diese virtuelle Umgebung installieren.

      Dazu benötigen wir zunächst Zugriff auf den Befehl virtualenv, den wir mit pip installieren können.

      Upgraden Sie pip und installieren Sie den Paket, indem Sie Folgendes eingeben:

      • sudo -H pip3 install --upgrade pip
      • sudo -H pip3 install virtualenv

      Das Flag -H stellt sicher, dass die Sicherheitsrichtlinie die home-Umgebungsvariable im Home-Verzeichnis des Zielbenutzers festlegt.

      Wenn virtualenv installiert ist, können wir mit der Erstellung unserer Umgebung beginnen. Erstellen und wechseln Sie in ein Verzeichnis, in dem wir unsere Projektdateien speichern können. Wir nennen es my_project_dir. Sie sollten jedoch einen Namen verwenden, der für Sie und das, woran Sie arbeiten, aussagekräftig ist.

      • mkdir ~/my_project_dir
      • cd ~/my_project_dir

      Innerhalb des Projektverzeichnisses erstellen wir eine virtuelle Python-Umgebung. Für den Zweck dieses Tutorials werden wir sie my_project_env nennen, aber Sie sollten sie so benennen, wie es für Ihr Projekt relevant ist.

      • virtualenv my_project_env

      Auf diese Weise wird ein Verzeichnis mit dem Namen my_project_env in Ihrem Verzeichnis my_project_dir erstellt. Darin wird eine lokale Version von Python und eine lokale Version von pip installiert. Wir können es nutzen, um eine isolierte Python-Umgebung für Jupyter zu installieren und zu konfigurieren.

      Bevor wir Jupyter installieren, müssen wir die virtuelle Umgebung aktivieren. Geben Sie hierzu Folgendes ein:

      • source my_project_env/bin/activate

      Ihre Eingabeaufforderung ändert sich und zeigt an, dass Sie jetzt innerhalb einer virtuellen Python-Umgebung arbeiten. Ihre Eingabeaufforderung sieht nun in etwa wie folgt aus: (my_project_env)user@host:~/my_project_dir$.

      Jetzt sind Sie bereit, Jupyter in diese virtuelle Umgebung zu installieren.

      Schritt 3 — Installieren von Jupyter

      Wenn Ihre virtuelle Umgebung aktiv ist, installieren Sie Jupyter mit der lokalen Instanz von pip.

      Anmerkung: Wenn die virtuelle Umgebung aktiviert ist (wenn Ihre Eingabe über (my_project_env) dieser voransteht), verwenden Sie pip anstelle von pip3, selbst wenn Sie Python 3 verwenden. Die Kopie der virtuellen Umgebung des Tools ist immer pip – unabhängig von der Python-Version.

      Jetzt haben Sie alle zur Ausführung von Jupyter benötigte Software erfolgreich installiert. Wir können nun den Notebook-Server starten.

      Schritt 4 — Ausführen von Jupyter Notebook

      Sie haben nun alles, was Sie brauchen, um Jupyter Notebook auszuführen! Um es auszuführen, führen Sie den folgenden Befehl aus:

      Ein Protokoll der Aktivitäten von Jupyter Notebooks wird auf das Terminal gedruckt. Wenn Sie Jupyter Notebook ausführen, läuft es auf einer bestimmten Portnummer. Das erste Notebook, das Sie ausführen, verwendet normalerweise Port 8888. Um die Portnummer, auf der Jupyter Notebook ausgeführt wird, zu überprüfen, prüfen Sie die Ausgabe des Befehls, der zum Starten verwendet wird:

      Output

      [I 21:23:21.198 NotebookApp] Writing notebook server cookie secret to /run/user/1001/jupyter/notebook_cookie_secret [I 21:23:21.361 NotebookApp] Serving notebooks from local directory: /home/sammy/my_project_dir [I 21:23:21.361 NotebookApp] The Jupyter Notebook is running at: [I 21:23:21.361 NotebookApp] http://localhost:8888/?token=1fefa6ab49a498a3f37c959404f7baf16b9a2eda3eaa6d72 [I 21:23:21.361 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [W 21:23:21.361 NotebookApp] No web browser found: could not locate runnable browser. [C 21:23:21.361 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=1fefa6ab49a498a3f37c959404f7baf16b9a2eda3eaa6d72

      Wenn Sie Jupyter Notebook auf einem lokalen Computer (nicht auf einem Server) ausführen, können Sie zur angezeigten URL navigieren, um eine Verbindung mit Jupyter Notebook herzustellen. Wenn Sie Jupyter Notebook auf einem Server ausführen, müssen Sie über SSH-Tunneling mit dem Server eine Verbindung herstellen, wie im nächsten Abschnitt beschrieben.

      Jetzt können Sie die SSH-Verbindung offen lassen und Jupyter Notebook weiter ausführen oder die App beenden und erneut ausführen, wenn Sie SSH-Tunneling eingerichtet haben. Wir wollen den Jupyter Notebook-Prozess stoppen. Wir führen ihn wieder aus, sobald wir SSH-Tunnel eingerichtet haben. Um den Jupyter Notebook-Prozess zu stoppen, drücken Sie STRG+C, geben Sie Y und dann zur Bestätigung ENTER ein. Die folgende Ausgabe wird angezeigt:

      Output

      [C 21:28:28.512 NotebookApp] Shutdown confirmed [I 21:28:28.512 NotebookApp] Shutting down 0 kernels

      Wir richten nun einen SSH-Tunnel ein, damit wir auf das Notebook zugreifen können.

      Schritt 5 — Verbinden mit dem Server mit SSH-Tunneling

      In diesem Abschnitt zeigen wir, wie wir mit der Weboberfläche von Jupyter Notebook eine Verbindung über SSH-Tunneling herstellen. Da Jupyter Notebook auf einem bestimmten Port auf dem Server ausgeführt wird (wie :8888, :8889 usw.), ermöglicht SSH-Tunneling eine sichere Verbindung mit dem Server-Port.

      Die nächsten beiden Unterabschnitte beschreiben, wie Sie einen SSH-Tunnel aus 1) einem Mac oder Linux oder 2) Windows erstellen. Siehe der Unterabschnitt für Ihren lokalen Computer.

      SSH-Tunneling mit einem Mac oder Linux

      Wenn Sie einen lokalen Mac- oder Linux-Computer verwenden, ähneln die Schritte zum Erstellen eines SSH-Tunnels der Anmeldung mit einem Remote-Server über SSH, mit Ausnahme der zusätzlichen Parameter im Befehl ssh. Dieser Unterabschnitt beschreibt die zusätzlichen Parameter, die im Befehl ssh für erfolgreiches Tunneling benötigt werden.

      SSH-Tunneling kann durch Ausführen des folgenden SSH-Befehls in einem neuen lokalen Terminalfenster erfolgen:

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

      Der Befehl ssh öffnet eine SSH-Verbindung, aber -L gibt an, dass der bestimmte Port auf dem lokalen (Client) Host remote-seitig (Server) an den bestimmten Host weitergeleitet werden soll. Das bedeutet, dass alles, was auf der zweiten Portnummer (z. B. 8888) auf dem Server auf der ersten Portnummer (z. B. 8888) auf dem lokalen Computer angezeigt wird.

      Optional ändern Sie Port 8888 in einen anderen Ihrer Wahl, um zu vermeiden, einen Port zu nutzen, der bereits in einem anderen Prozess verwendet wird.

      server_username ist Ihr Benutzername (z. B. sammy) auf dem Server, den Sie erstellt haben, und your_server_ip lautet die IP-Adresse Ihres Servers.

      Für den Benutzernamen sammy und die Adresse des Servers <^>203.0.113.0^> wäre der Befehl:

      • ssh -L 8888:localhost:8888 sammy@203.0.113.0

      Wenn nach Ausführung des Befehls ssh-L kein Fehler angezeigt wird, können Sie in Ihre Programmierumgebung wechseln und Jupyter Notebook ausführen:

      Sie erhalten eine Ausgabe mit einer URL. Öffnen Sie von einem Webbrowser auf Ihrem lokalen Rechner die Weboberfläche von Jupyter Notebook mit der URL, die mit http://localhost:8888 beginnt. Stellen Sie sicher, dass die Token-Nummer enthalten ist oder geben Sie die Token-Nummer, wenn Sie dazu aufgefordert werden, unter http://localhost:8888 ein.

      SSH-Tunneling mit Windows und Putty

      Wenn Sie Windows verwenden, können Sie einen SSH-Tunnel mit Putty erstellen.

      Geben Sie zunächst die Adresse des Servers oder die IP-Adresse als Hostnamen ein, wie hier dargestellt:

      Hostname für SSH-Tunnel festlegen

      Klicken Sie dann unten im linken Fenster auf SSH, um das Menü auszuklappen und klicken Sie anschließend auf Tunnels. Geben Sie die lokale Portnummer ein, die Sie zum Zugriff auf Jupyter auf Ihrem lokalen Computer verwenden möchten. Wählen Sie 8000 oder höher aus, um Ports zu vermeiden, die von anderen Diensten verwendet werden, und setzen Sie das Ziel als localhost:8888 fest (wobei :8888 der Port-Nummer entspricht, auf der das Jupyter Notebook ausgeführt wird).

      Klicken Sie nun auf die Schaltfläche Add (hinzufügen). Die Ports sollten in der Liste Forwarded ports angezeigt werden:

      Forwarded Ports Liste

      Klicken Sie abschließend auf die Schaltfläche Open, um eine Verbindung zum Server über SSH herzustellen und die gewünschten Ports zu tunneln. Navigieren Sie im Browser zu http://localhost:8000 (oder einen anderen beliebigen Port), um sich mit dem Jupyter Notebook zu verbinden, das auf dem Server ausgeführt wird. Stellen Sie sicher, dass die Token-Nummer enthalten ist oder geben Sie die Token-Nummer unter http://localhost:8888 ein, wenn Sie dazu aufgefordert werden.

      Schritt 6 — Verwenden von Jupyter Notebook

      Dieser Abschnitt beschreibt die Grundlagen der Verwendung von Jupyter Notebook. Wenn Sie Jupyter Notebook nicht bereits ausführen, starten Sie es mit dem Befehl jupyter notebook.

      Sie sollten nun damit über einen Webbrowser verbunden sein. Jupyter Notebook ist ein sehr leistungsfähiges Tool mit vielen Funktionen. Dieser Abschnitt beschreibt einige grundlegende Funktionen für den Einstieg ins Notebook. Jupyter Notebook zeigt alle Dateien und Ordner im Verzeichnis an, aus dem es ausgeführt wird. Wenn Sie also an einem Projekt arbeiten, müssen Sie sie aus dem Projektverzeichnis starten.

      Um eine neue Notebook-Datei zu erstellen, wählen Sie New > Python 3 aus dem Pull-down-Menü oben rechts:

      Erstellen eines neuen Python 3 Notebooks

      Das öffnet ein Notebook. Wir können nun Python-Code in der Zelle ausführen oder die Zelle in Markdown ändern. Ändern Sie beispielsweise die erste Zelle, um Markdown zu akzeptieren, indem Sie über die obere Navigationsleiste auf Cell > Cell Type > Markdown klicken. Wir können nun Notizen mit Markdown schreiben und sogar Gleichungen einschließen, die in LaTeX geschrieben wurden, indem wir Sie zwischen die Symbole $$ setzen. Geben Sie beispielsweise Folgendes in die Zelle ein, nachdem Sie sie in Markdown geändert haben:

      # First Equation
      
      Let us now implement the following equation:
      $$ y = x^2$$
      
      where $x = 2$
      

      Um Markdown in Rich-Text zu verwandeln, betätigen Sie die Tasten CTRL und ENTER. Sie erhalten eine Ausgabe, die etwa folgendermaßen aussieht:

      Markdown-Ergebnisse

      Sie können die Markdown-Zellen nutzen, um Notizen zu machen und Ihren Code zu dokumentieren. Wir wollen diese Gleichung implementieren und das Ergebnis drucken. Klicken Sie auf die Zelle oben und betätigen Sie dann gleichzeitig die Tasten ALT und ENTER, um eine Zelle darunter hinzuzufügen.

      x = 2
      y = x**2
      print(y)
      

      Um den Code auszuführen, betätigen Sie CTRL+ENTER. Sie erhalten die folgenden Ergebnisse:

      Ergebnisse der ersten Gleichung

      Sie haben nun die Möglichkeit, Module zu importieren und das Notebook so zu verwenden, wie in jeder anderen Python-Entwicklungsumgebung!

      Zusammenfassung

      Herzlichen Glückwunsch! Sie sollten nun reproduzierbaren Python-Code und Notizen in Markdown mit Jupyter Notebook schreiben können. Um Jupyter Notebook aus der Oberfläche heraus schnell kennenzulernen, wählen Sie Help > User Interface Tour aus dem Navigationsmenü oben.

      Von hier aus können Sie ein Datenanalyse- und Visualisierungsprojekt beginnen, indem Sie Data Analysis und Visualisierung mit Pandas und Jupyter Notebook in Python 3 lesen.



      Source link

      How To Set Up Jupyter Notebook with Python 3 on Ubuntu 20.04 and Connect via SSH Tunneling


      Introduction

      Jupyter Notebook is an open-source web application that lets you create and share interactive code, visualizations, and more. This tool can be used with several programming languages, including Python, Julia, R, Haskell, and Ruby. It is often used for working with data, statistical modeling, and machine learning.

      Jupyter Notebooks (or just “Notebooks”) are documents produced by the Jupyter Notebook app which contain both computer code and rich text elements (paragraph, equations, figures, links, etc.) which aid in presenting and sharing reproducible research. They can therefore be an excellent tool to use for data-driven or programming-based presentations, or as a teaching tool.

      This tutorial will walk you through setting up Jupyter Notebook to run from an Ubuntu 20.04 server, as well as demonstrate how to connect to and use the notebook from a local machine via tunnelling. By the end of this guide, you will be able to run Python 3 code using Jupyter Notebook running on a remote server.

      Prerequisites

      In order to complete this guide, you should have a fresh Ubuntu 20.04 server instance with a basic firewall and a non-root user with sudo privileges configured. You can learn how to set this up by running through our initial server setup tutorial.

      Step 1 — Set Up Python

      To begin the process, we’ll install the dependencies we need for our Python programming environment from the Ubuntu repositories. Ubuntu 20.04 comes preinstalled with Python 3. We will use the Python package manager pip to install additional components a bit later.

      We first need to update the local apt package index and then download and install the packages:

      Next, install pip and the Python header files, which are used by some of Jupyter’s dependencies:

      • sudo apt install python3-pip python3-dev

      We can now move on to setting up a Python virtual environment into which we’ll install Jupyter.

      Step 2 — Create a Python Virtual Environment for Jupyter

      Now that we have Python 3, its header files, and pip ready to go, we can create a Python virtual environment to manage our projects. We will install Jupyter into this virtual environment.

      To do this, we first need access to the virtualenv command which we can install with pip.

      Upgrade pip and install the package by typing:

      • sudo -H pip3 install --upgrade pip
      • sudo -H pip3 install virtualenv

      The -H flag ensures that the security policy sets the home environment variable to the home directory of the target user.

      With virtualenv installed, we can start forming our environment. Create and move into a directory where we can keep our project files. We’ll call this my_project_dir, but you should use a name that is meaningful for you and what you’re working on.

      • mkdir ~/my_project_dir
      • cd ~/my_project_dir

      Within the project directory, we’ll create a Python virtual environment. For the purpose of this tutorial, we’ll call it my_project_env but you should call it something that is relevant to your project.

      • virtualenv my_project_env

      This will create a directory called my_project_env within your my_project_dir directory. Inside, it will install a local version of Python and a local version of pip. We can use this to install and configure an isolated Python environment for Jupyter.

      Before we install Jupyter, we need to activate the virtual environment. You can do that by typing:

      • source my_project_env/bin/activate

      Your prompt should change to indicate that you are now operating within a Python virtual environment. Your command prompt will now read something like this: (my_project_env)user@host:~/my_project_dir$.

      At this point, you’re ready to install Jupyter into this virtual environment.

      Step 3 — Install Jupyter

      With your virtual environment active, install Jupyter with the local instance of pip.

      Note: When the virtual environment is activated (when your prompt has (my_project_env) preceding it), use pip instead of pip3, even if you are using Python 3. The virtual environment’s copy of the tool is always named pip, regardless of the Python version.

      At this point, you’ve successfully installed all the software needed to run Jupyter. We can now start the Notebook server.

      Step 4 — Run Jupyter Notebook

      You now have everything you need to run Jupyter Notebook! To run it, execute the following command:

      A log of the activities of the Jupyter Notebook will be printed to the terminal. When you run Jupyter Notebook, it runs on a specific port number. The first Notebook you run will usually use port 8888. To check the specific port number Jupyter Notebook is running on, refer to the output of the command used to start it:

      Output

      [I 21:23:21.198 NotebookApp] Writing notebook server cookie secret to /run/user/1001/jupyter/notebook_cookie_secret [I 21:23:21.361 NotebookApp] Serving notebooks from local directory: /home/sammy/my_project_dir [I 21:23:21.361 NotebookApp] The Jupyter Notebook is running at: [I 21:23:21.361 NotebookApp] http://localhost:8888/?token=1fefa6ab49a498a3f37c959404f7baf16b9a2eda3eaa6d72 [I 21:23:21.361 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [W 21:23:21.361 NotebookApp] No web browser found: could not locate runnable browser. [C 21:23:21.361 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=1fefa6ab49a498a3f37c959404f7baf16b9a2eda3eaa6d72

      If you are running Jupyter Notebook on a local computer (not on a server), you can navigate to the displayed URL to connect to Jupyter Notebook. If you are running Jupyter Notebook on a server, you will need to connect to the server using SSH tunneling as outlined in the next section.

      At this point, you can keep the SSH connection open and keep Jupyter Notebook running or you can exit the app and re-run it once you set up SSH tunneling. Let’s choose to stop the Jupyter Notebook process. We will run it again once we have SSH tunneling set up. To stop the Jupyter Notebook process, press CTRL+C, type Y, and then ENTER to confirm. The following output will be displayed:

      Output

      [C 21:28:28.512 NotebookApp] Shutdown confirmed [I 21:28:28.512 NotebookApp] Shutting down 0 kernels

      We’ll now set up an SSH tunnel so that we can access the Notebook.

      Step 5 — Connect to the Server Using SSH Tunneling

      In this section we will demonstrate how to connect to the Jupyter Notebook web interface using SSH tunneling. Since Jupyter Notebook will run on a specific port on the server (such as :8888, :8889 etc.), SSH tunneling enables you to connect to the server’s port securely.

      The next two subsections describe how to create an SSH tunnel from 1) a Mac or Linux, or 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 local computer, the steps for creating an SSH tunnel are similar to using SSH to log in to your remote server, except that there are additional parameters in the ssh command. This subsection will outline the additional parameters needed in the ssh command to tunnel successfully.

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

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

      The ssh command opens an SSH connection, but -L specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side (server). This means that whatever is running on the second port number (e.g. 8888) on the server will appear on the first port number (e.g. 8888) on your local computer.

      Optionally change port 8888 to one of your choosing to avoid using a port already in use by another process.

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

      For example, for the username sammy and the server address 203.0.113.0, the command would be:

      • ssh -L 8888:localhost:8888 sammy@203.0.113.0

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

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

      SSH Tunneling with Windows and Putty

      If you are using Windows, you can create an SSH tunnel using Putty.

      First, enter the server URL or IP address as the hostname as shown:

      Set Hostname for SSH Tunnel

      Next, click SSH on the bottom of the left pane to expand the menu, and then click Tunnels. Enter the local port number you want to use to access Jupyter on your local machine. Choose 8000 or greater to avoid 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 click the Add button, and the ports should appear in the Forwarded ports list:

      Forwarded ports list

      Finally, click the Open button 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 token number is included, or enter the token number string when prompted at http://localhost:8000.

      Step 6 — Using Jupyter Notebook

      This section goes over the fundamentals of using Jupyter Notebook. If you don’t currently have Jupyter Notebook running, start it with the jupyter notebook command.

      You should now be connected to it using a web browser. Jupyter Notebook is a very powerful tool with many features. This section will outline a few basic features to get you started using the Notebook. Jupyter Notebook will show all of the files and folders in the directory it is run from, so when you’re working on a project make sure to start it from the project directory.

      To create a new Notebook file, select New > Python 3 from the top right pull-down menu:

      Create a new Python 3 notebook

      This will open a Notebook. We can now run Python code in the cell or change the cell to markdown. For example, change the first cell to accept Markdown by clicking Cell > Cell 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, type the following into the cell after changing it to markdown:

      # First Equation
      
      Let us now implement the following equation:
      $$ y = x^2$$
      
      where $x = 2$
      

      To turn the markdown into rich text, press the CTRL and ENTER keys. You should receive output similar to the following:

      results of markdown

      You can use the markdown cells to make notes and document your code. Let’s implement that equation and print the result. Click on the top cell, then press the ALT and ENTER keys together to add a cell below it. Enter the following code in the new cell.

      x = 2
      y = x**2
      print(y)
      

      To run the code, press CTRL+ENTER. You’ll receive the following results:

      first equation results

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

      Conclusion

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

      From here, you can begin a data analysis and visualization project by reading Data Analysis and Visualization with pandas and Jupyter Notebook in Python 3.



      Source link