Mehmet Bektas
Jupyter Blog
Published in
7 min readFeb 19, 2024

--

Python environment management in JupyterLab Desktop

We are pleased to announce Python environment management features recently added to JupyterLab Desktop (JLD). Now you can create new Python environments and manage existing ones on your system, right from JupyterLab Desktop UI.

Python environment management dialog

Python environments and their use in JupyterLab Desktop

The standard distribution of JupyterLab is a Web Application which is available as a Python package named “jupyterlab”. JupyterLab Desktop makes installing and launching JupyterLab much easier by bundling it together with Python and other scientific computing dependencies in the form of a Python environment.

Python environments provide isolation of package installations and they let you work on different projects with different set of packages and/or package versions. JLD comes with a bundled Python environment installer and lets users install it as the default environment for the app from the UI and effortlessly. It can also use existing Python environments on a system to launch JupyterLab web app.

JupyterLab Desktop — Python environment selection

With the latest updates, JLD supports creating custom Python environments from the UI and the CLI. Bundled environment can now be installed to multiple locations, as different virtual environments. JLD also allows you to create new environments by downloading packages from conda or PyPI registries.

Why support environment management in JupyterLab Desktop?

It is common for our users to use different Python environments for different projects as they may require different set of Python packages or package versions. Also, in order to use a Python environment in JLD, certain requirements need to be satisfied, such as existence of “jupyterlab” package. These are some of the motivations behind adding support for Python environment management to JupyterLab Desktop.

Normally, creating a Python environment requires installing Python and/or conda onto the system first and getting familiar with terminal commands required to manage the environments. JLD simplifies this process by eliminating the need to make additional installations and by providing a user friendly interface, making it possible to create new environments with few UI clicks.

conda and Python are shipped with JupyterLab Desktop within its bundled environment installer. Once the bundled environment is installed then JLD can use the bundled conda and Python to create new environments without requiring any further conda/Python installation from the user.

Python environments created in JLD are compatible with the application itself and they are added to the environment registry of JLD automatically for use in sessions. This prevents dealing with compatibility issues and manually adding environments to JLD registry.

Python environment management dialog

JupyterLab Desktop now has a new dialog which lets you manage Python environments and settings. You can access this dialog by clicking “Manage Python environments” menu item on session menu (hamburger menu on top-right).

Managing existing environments

“Environments” tab lists the environments discovered on your system. If you have other compatible environments available on your system but not discovered then you can add those by clicking “Add existing” button. You can choose the Python executable path in the system dialog that will be shown and the environment will be validated and added to JLD registry. Any validation errors will be shown above the environment list.

Python environment context menu

You can hover over the environment list to see additional details on the environment such as JupyterLab version. You can access actions for each environment by clicking the menu on the right end of the row. You can copy the Python path or detailed environment info to clipboard by using the first two menu items. Clicking “Launch Terminal” opens a system terminal and activates the selected environment. You can browse the environment’s file system by clicking “Reveal in Finder/Explorer” . “Delete” action is available for environments created by JLD. It lets you remove the environment installation from your system.

Creating new environments

“Create new” tab lets you create new environments using the bundled installer or packages from registry.

“Copy of the bundled environment” installs a copy of the bundled environment in a different location on your system. You can set a name for it and the installation path will be shown below. The parent directory for new environment installations can be configured as will be shown in the sections below.

Create new environment using bundled installer

“New environment” option lets you create a new environment from scratch by downloading packages from conda or PyPI registries based on your environment type selection. In order to be compatible with JLD, “jupyterlab” Python package is installed into the environment by default. You can uncheck “Include jupyterlab” if you don’t plan to use the environment with JLD. You can install additional Python packages into the environment using “Additional Python packages” field and by entering the list of packages separated by space. The preview of the environment create command will be shown below. You can click “Show output” during installation to see the progress or to inspect the output from installer.

Create new environment using packages from registry

Newly created environments will be listed in “Environments” tab and they will be available to use in JLD sessions immediately.

Python environment settings

“Settings” tab lets you set Python environment configuration for JLD. The settings on this dialog are auto populated based on defaults or information discovered on your system.

Python environment settings

The default Python environment to use for JLD can be set on the top. This setting used to be in the “Settings dialog” and moved here.

“New Python environment install directory” defines the parent directory for newly created environments.

“conda path” is the path of conda executable to use to create new conda environments and to activate conda sub environments.

“conda channels” sets the channels to use when installing conda packages.

Python path setting at the bottom controls which Python executable to use when creating new venv environments.

Updates to Python environment selection popup

When local JupyterLab Desktop sessions are created, the active environment information is shown on top-right section of the title bar. This session info button is clickable and when clicked it shows the Python environment selection popup. New features are added to this popup with the latest release.

On top row of this popup, the current Python path used in the session is shown now. There are two new buttons on the right of this path. The first one lets you restart the JupyterLab server running for the session. This could be useful to restart JupyterLab web app after installing packages, without restarting the whole app. The second button lets you copy session information to the clipboard, such as the URL of the JupyterLab server running.

Session environment info and action buttons

Now you can filter the Python environments listed on the environment select popup. As you type into the path filter field, the environments will be filtered by the match in Python path.

Filter Python environments

Clicking the gear icon next to filter input field takes you to the Python environment management dialog.

Updating bundled Python environment installation

When JupyterLab Desktop is updated, the bundled Python environment installation is not updated automatically. There wasn’t a clear indication of this out of sync installation and users had to go to Settings dialog to manually update the bundled environment.

Now with the latest version, notification badge is shown when the environment update is available and auto-update of the bundled environment installation made possible. You can configure the environment update options on “Advanced” tab of the “Settings dialog”. Note that “Update bundled environment automatically when app is updated” option will delete the existing installation and make a fresh install of the bundled environment.

Bundled environment update settings

When there is an update available for the bundled environment installation a notification badge is shown on the session title bar with a red circle over the server icon.

Bundled environment update notification badge

Also, a new action button is shown on environment selection popup on the right of the current Python path label, in orange color. You can update the bundled environment installation by simply clicking this button.

Bundled environment update button

Bundled environment updates require app restart and update is installed before the next launch of the application.

Bundled environment update progress

Coming up next!

Stay tuned for my next blog post which will be on the Python environment management using JupyterLab Desktop CLI! CLI commands provide additional options for creating Python environments such as installation using environment definition files and conda-pack bundles.

Try it out and share your feedback!

Try the latest JupyterLab Desktop and share your feedback with us using project’s GitHub issues! User feedback from the community shapes the project roadmap.

For more information and updates on the project, follow us on GitHub and Jupyter Blog.

About the Author

Mehmet Bektas is a Senior Software Engineer at Netflix and a Jupyter Distinguished Contributor. He maintains and contributes to JupyterLab, JupyterLab Desktop and several other projects in the Jupyter eco-system.

--

--

Senior Software Engineer at Netflix. Jupyter Distinguished Contributor.