6

Python environment management using JupyterLab Desktop CLI

 1 month ago
source link: https://blog.jupyter.org/python-environment-management-using-jupyterlab-desktop-cli-e57485c9287c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python environment management using JupyterLab Desktop CLI

Published in
4 min readMar 1, 2024

JupyterLab Desktop (JLD) CLI provides several commands and options to manage Python environments for use in the application. In my previous blog post I had covered using JLD UI to manage Python environments. You can use jlab CLI commands to do the same and for additional environment management options.

Setting up jlab CLI

JupyterLab Desktop installers for Windows and Linux create jlab CLI command as part of the installation process. On macOS, the CLI command is created at first program launch. Since this requires elevated user permissions, users may need to do a one time manual approval on macOS UI. Visit Settings dialog on macOS to verify that CLI command is installed properly.

1*HS9E-UDLEIo2U0qvMFngeA.png

jlab CLI status on Settings dialog

Setting up CLI is only an operation to configure the command for use in the Terminal. It doesn’t install any additional software, the functionality is already built into the desktop app.

jlab env CLI commands

“jlab env <action> [options]” CLI commands provide environment management functionality. Below are the list of actions supported with overview of each one. Each action can have a variety of parameter options. See the Python environment management CLI documentation on JLD GitHub repo for the details on parameter options.

Under the hood, these commands use conda and pip that are available on your system. conda and pip could be pre-installed or they become available with the bundled Python environment installation.

jlab env info

This command prints app’s Python environment configuration on the system. JLD initializes this config at launch time by discovering the Python configuration on your system. These settings can be updated by using the UI or CLI commands that are listed below.

1*KRDJFM_g3Jauf4FO3cxxiw.png

jlab env info command output

jlab env list

Lists discovered and user set Python environments available to the app. Python paths, python and jupyterlab package versions and whether it was created by JLD are also listed.

1*lgXUXSxJYoR82UQoWe4XbQ.png

jlab env list command output

jlab env create

Creates a new Python environment and adds to the application registry, making it ready to use by the app. Environments can be created by using the bundled environment installer or by downloading packages from registry. “jupyterlab” Python package is required for compatibility with JLD and it is automatically installed in most cases. Additional Python packages and conda channels to use can also be specified.

This CLI command provides more options compared to Python environment management UI. Additional environment sources can be used. You can create an environment from a pre-archived conda-pack bundle, conda-lock file or a conda environment file in addition to options available on the UI. These source files can be local file paths on the system or remote URLs.

Using remote sources, environments can be created using archives and environment definition files created by conda-store and similar tools.

Additional list of packages can be installed on top of packages defined in an environment definition file. Below is an example of creating a numpy environment using a remote environment definition file and installing scikit-learn in addition.

1*-PEjCqxG5nEddcZRVulleg.png

jlab env create commad example

jlab env activate

Activates a Python environment in system Terminal. Environments can be activated by name or full prefix path.

jlab env set-python-envs-path

Sets Python environment install directory used when creating new environments.

jlab env set-conda-path

Sets the base conda executable path. Base conda executable is used when creating new conda environments, and running conda commands by the app.

jlab env set-conda-channels

Sets conda channels to use when installing new conda packages.

jlab env set-system-python-path

Sets Python executable path to use when creating new venv environments.

jlab env update-registry

Updates the app environment registry. This command checks all the environments registered for compatibility and fetches Python and jupyterlab versions. This action is normally done at desktop app launch.

Setting project Python environments using CLI

You can set the Python environment used for a project very easily by using the Python environment selection popup on the UI. You can also set it by using the CLI command “jlab config set”.

Below is an example command to set a project’s Python environment using jlab CLI.

1*hJV8jjrhpQFsq019FV3AqA.png

jlab config set commad to set project Python path

Additional resources

For additional details on environment management CLI commands see the Python environment management CLI documentation at JupyterLab Desktop GitHub repo. Command parameters and options with plenty of examples can be found there.

JLD provides other CLI commands to launch and configure the application. Check out the CLI documentation for other available commands.

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK