JupyterLab for an Enhanced Notebook Experience :

JupyterLab for an Enhanced Notebook Experience
by:
blow post content copied from  Real Python
click here to view original post


Maybe you’ve already worked with Jupyter Notebooks from Project Jupyter to create documents containing runnable code. You can achieve even more with JupyterLab, a tool kit that you can use to document and share your research, teaching, and learning activities. It’s useful in a wide range of disciplines, from data analysis and data visualization to scientific study.

JupyterLab enhances your notebooks by providing a browser-based interface that allows you to use multiple notebooks together effectively. In addition, it offers you a comprehensive Markdown editor, file manager, file viewer, and an infrastructure that enables you to run code from a wide range of files.

In this tutorial, you’ll learn how to:

  • Share code between multiple Jupyter Notebooks
  • Debug a Jupyter Notebook
  • Create and manage Markdown files
  • Run embedded code from a range of different files
  • Manage and view different file types from a single interface
  • Access your operating system from within JupyterLab

Jupyter is a portmanteau word blended from the three programming languages Julia, Python, and R. Although you’ll focus on Python in this tutorial, you can use Jupyter with the other languages as well. Plus, this free application works on macOS, Linux, and Windows environments.

JupyterLab takes Jupyter Notebook usage to a different level, so you’ll get the most out of this tutorial if you’re already familiar with Jupyter Notebook.

Installing and Starting JupyterLab

The cleanest way of installing JupyterLab on a computer is to use a virtual environment. This will ensure that your JupyterLab work doesn’t interfere with any other Python projects or environments that you may already have. For this tutorial, you’ll create a new virtual environment named jl_venv. Select your operating system to get JupyterLab up and running:

If you haven’t already done so, download and install Python on your Windows computer. Then fire up a Windows PowerShell(Admin) or Terminal(Admin) prompt depending on the version of Windows that you’re using. Now type in the following commands:

Windows PowerShell
PS> mkdir jupyterlab_projects
PS> cd jupyterlab_projects
PS> python -m venv jl_venv
PS> jl_venv\Scripts\activate
(jl_venv) PS> python -m pip install jupyterlab

To keep things neat, you first create a new jupyterlab_projects folder for all of your JupyterLab work. Later you’ll create individual subfolders for each of your projects to keep everything organized.

Next, you create a virtual environment named jl_venv within this folder, which you then activate. If the activation is successful, then the virtual environment’s name will precede your Powershell prompt. If not, see the alert box below. Finally, you install JupyterLab into this virtual environment.

As you can see above, you have a PowerShell prompt that’s preceded by (jl_venv). This means anything you do from this point forward will stay in this environment and remain separate from any other Python work that you may have elsewhere.

Finally, for neatness, you’ll create a new folder named tutorial_project. This will serve as a working area for this tutorial. Then you start up JupyterLab from within it:

Windows PowerShell
(jl_venv) PS> mkdir tutorial_project
(jl_venv) PS> cd tutorial_project
(jl_venv) PS> jupyter lab

To install JupyterLab, fire up a terminal and run the following commands:

Shell
$ mkdir jupyterlab_projects
$ cd jupyterlab_projects
$ python3 -m venv jl_venv
$ source jl_venv/bin/activate
(jl_venv) $ python -m pip install jupyterlab

To keep things neat, you first create a new jupyterlab_projects directory for all of your JupyterLab work. Later you can create individual subdirectories for each of your projects to keep things organized.

Next, you create a virtual environment named jl_venv. If this command fails, see the alert box below. You then activate your virtual environment by running its activation script. Once the virtual environment is activated, its name precedes your terminal prompt. You install JupyterLab into this virtual environment.

Your terminal prompt now shows that (jl_venv) is the active environment. This means anything you do from this point forward will happen in this environment and remain separate from any other Python work that you may have elsewhere.

Finally, for neatness, you’ll create a new directory named tutorial_project and then start up JupyterLab from within it:

Shell
(jl_venv) $ mkdir tutorial_project
(jl_venv) $ cd tutorial_project
(jl_venv) $ jupyter lab

To install JupyterLab, fire up a terminal and run the following commands:

Shell
$ mkdir jupyterlab_projects
$ cd jupyterlab_projects
$ python -m venv jl_venv
$ source jl_venv/bin/activate
(jl_venv) $ python -m pip install jupyterlab

To keep things neat, you first create a new jupyterlab_projects folder for all of your JupyterLab work. Later you can create individual subfolders for each of your projects to keep things organized.

Next, you create a virtual environment named jl_venv. You then activate your virtual environment by running its activation script. Once the virtual environment is activated, its name precedes your terminal prompt. You install JupyterLab into this virtual environment.

Finally, for neatness, you’ll create a new folder named tutorial_project and then start up JupyterLab from within it:

Shell
(jl_venv) $ mkdir tutorial_project
(jl_venv) $ cd tutorial_project
(jl_venv) $ jupyter lab

Of course, once you’ve finished this tutorial, you can delete tutorial_project and add in your own project-specific folders instead.

JupyterLab will start in your web browser, all ready for you to use. But before you dive in, you might want to know how to end your session:

  • To shut JupyterLab down, make sure everything is saved, and then use FileShut Down to close the application before closing your browser. This will close everything down cleanly. Closing the browser alone doesn’t close the server, while crashing the server may cause data loss.

  • To restart, open either Powershell or your terminal, navigate to your jupyterlab_projects folder, then activate jl_venv. Finally, create or enter your specific project’s folder then start JupyterLab as before.

  • To deactivate your virtual environment, use the deactivate command. Your command prompt will return to normal.

Once you’ve installed and started JupyterLab, its server will start, along with a web browser connection to it. It may take a moment, but soon you’ll be looking at its main interface:

main jupyterlab interface

Because this is your first time running JupyterLab, the front screen shown above contains only a single Launcher window. This is where you can access everything else that’s on offer.

In the upcoming sections, you’ll perform a range of tasks highlighting how JupyterLab’s tools enhance the capability of notebooks. You’ll also see some other interesting features as well.

Understanding JupyterLab Kernels

JupyterLab’s tools support you in your work. Although the tools are self-contained, by using some of them together, you get more out of them. This integration is probably JupyterLab’s most powerful feature.

A good starting point when learning JupyterLab is for you to know what its basic components are and how to make them work together. The diagram below shows an overview of these:

Diagram showing the components of JupyterLab

This diagram may look overwhelming at first because there are several parts. Don’t worry, you’ll soon see their relevance. The arrows show how various components interact. These interactions are one of the great benefits of JupyterLab. You’ll start with the central part of the application and the diagram: the kernel.

Read the full article at https://realpython.com/using-jupyterlab/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]


November 13, 2023 at 07:30PM
Click here for more details...

=============================
The original post is available in Real Python by
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================

Salesforce